Last active
June 14, 2024 07:44
[TOO OLD, ARCHIVED] How to use nanoid with TypeScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nanoid from 'nanoid'; | |
console.log(nanoid()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// types/nanoid.d.ts | |
declare module 'nanoid' { | |
export default function nanoid(size?: number): string; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"compilerOptions": { | |
"target": "es5", | |
"module": "commonjs", | |
"lib": [ | |
"es2015", | |
"dom" | |
], | |
"strict": true, | |
"typeRoots": [ | |
"types", | |
"node_modules/@types" | |
], | |
"esModuleInterop": true | |
} | |
} |
This is insane.
I looked at this gist for the first time in six years, but we don't need it anymore.
nanoid provides d.ts now. https://github.com/ai/nanoid/blob/main/index.d.ts
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doesn't seems to work with nanoid v5.0.3