TypeScript support
July 14, 2023 ยท View on GitHub
FingerprintJS has built-in TypeScript types.
In order to use them, just install the library and import it in a .ts file:
npm i @fingerprintjs/fingerprintjs
# or
yarn add @fingerprintjs/fingerprintjs
import FingerprintJS from '@fingerprintjs/fingerprintjs'
FingerprintJS officially supports TypeScript version 5.1,
but may work with newer and older versions of TypeScript.
If you face a TypeScript error that occurs in a .d.ts file provided by FingerprintJS
(example 1, example 2),
consider any of these solutions:
- Update the TypeScript package in your project to version 5.1 or newer
npm i typescript@^5.1 # or yarn add typescript@^5.1 - Prevent TypeScript from using the library types. To do it, replace
withimport ... from '@fingerprintjs/fingerprintjs'
in yourimport ... from '@fingerprintjs/fingerprintjs/dist/fp.esm'.tsfiles, and add the following line to a.d.tsfile (if there is no such file, create one anywhere with any name):declare module '@fingerprintjs/fingerprintjs/dist/fp.esm'