Skip to content

TypeScript support

Tyler Vigario edited this page Jul 7, 2024 · 5 revisions

Importing

Use "moduleResolution": "node16" or "moduleResolution": "nodenext" in your tsconfig.json.

ESM

{
  "compilerOptions": {
    "target": "ES6",
    "module": "NodeNext",
    "moduleResolution": "nodenext",
  },
}
import n2words from 'n2words/i18n/en.js'

console.log(n2words(100)) // "one hundred"

CommonJS

{
  "compilerOptions": {
    "target": "ES6",
    "module": "NodeNext",
    "moduleResolution": "nodenext",
  },
}
import('n2words/i18n/en.js').then(({default: n2words}) => {
    console.log(n2words(100)) // "one hundred"
})

Typings

We offer generated typings within our NPM package. There is no need to create your own or use // @ts-ignore anymore. If you are having trouble with any typings, open an issue here on GitHub; we'll be sure to fix it.

Example Repo

I've created a minimal test repo to proactively monitor the state of importing in TypeScript.

Clone this wiki locally