Skip to content

TypeScript support

Tyler Vigario edited this page Oct 11, 2023 · 4 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 of the typings feel free to open an issue here on GitHub and we'll be sure to resolve it.

Example Repo

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