A type detection utility for JavaScript

Usage no npm install needed!

<script type="module">
  import sapphireType from 'https://cdn.skypack.dev/@sapphire/type';


Sapphire Logo


A type detection utility for JavaScript.

GitHub codecov npm bundle size npm

Table of Contents


Sometimes there is a need to know what a value's type of something is, this package exists to satisfy those needs by implementing a parser that can retrieve the type of the value recursively and process a string similar to TypeScript's types.


  • Written in TypeScript
  • Bundled with Rollup so it can be used in NodeJS and browsers
  • Offers CommonJS, ESM and UMD bundles
  • Fully tested


yarn add @sapphire/type
# npm install @sapphire/type


Note: While this section uses require, the imports match 1:1 with ESM imports. For example const { Type } = require('@sapphire/type') equals import { Type } from '@sapphire/type'.

Note: When using ESM syntax you can also default-import Type class: import Type from '@sapphire/type'.

Note: The internal functions of getPromiseDetails and getProxyDetails are also exported. If you don't know what these are, then you need not be concerned about this.

Basic Usage

// Import the Type class
const { Type } = require('@sapphire/type');

// Define a Type with an array of two numbers
const type = new Type([1, 2]);

// Logs: Array<number>

Buy us some doughnuts

Sapphire Community is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!

We accept donations through Open Collective, Ko-fi, PayPal, Patreon and GitHub Sponsorships. You can use the buttons below to donate through your method of choice.

Donate With Address
Open Collective Click Here
Ko-fi Click Here
Patreon Click Here
PayPal Click Here

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Jeroen Claassens


Gryffon Bellish








Vlad Frangu


This project follows the all-contributors specification. Contributions of any kind welcome!