I’m trying to use the library ‘timezoner’ in my Typescript function and I have imported the library via the sidebar, but I’m unable to use it due to the following error:
Cannot find module 'timezoner";' or its corresponding type declarations.typescript(2307)
Are there any additional steps required to make this work? Do I have to define my own d.types file?
For all NPM libraries that you want to use within a TypeScript context, you’ll need type definitions.
Given that timezoner
doesn’t publish its own type definitions, nor is there a DefinitelyTyped
(https://github.com/DefinitelyTyped/DefinitelyTyped) package with definitions for timezoner
, you will need to declare your own types.
The External Definitions
section of the TypeScript documentation (https://www.typescriptlang.org/docs/handbook/2/type-declarations.html#external-definitions) should contain all the information you need. There’s a section on both declaring your own types or just declaring the module without any types, and using it in a slightly unsafe, untyped manner.