I am trying to include a .d.ts file in my npm package for my (non-TypeScript) library.
I have the following in my package.json:
"typings": "./src/iter.d.ts",
But no matter what I put in ./src/iter.d.ts, whenever I try to use it in Visual Studio, I always get a "Cannot find module 'iterjs'" message.
To reproduce, create a new TypeScript app in VS (I'm using 2015 with TS 1.8.4), do an npm install iterjs, and add the following to app.ts:
import iter from 'iterjs';
I've tried modifying the local copy of iter.d.ts (under node_modules) in a desperate attempt to get anything working at all; my local copy currently has only the following content:
export declare function bob(object: Object, property: string): boolean;
export default bob;
I can verify that Visual Studio is finding and reading the iter.d.ts file (I can see it being read in Process Monitor every time VS opens app.ts); however, there's apprently something in the .d.ts file it doesn't like. I have read about a dozen blog posts, gone through the Handbook, and a half-dozen TypeScript issues on the subject, and have tried about 20 different ways of exporting anything from the .d.ts file, but VS always just gives the same error (Cannot find module 'iterjs').
Node-like resolution of .d.ts files in NPM packages only works for type definitions in proper external module format. The .d.ts in your repository is in ambient module format, to convert it to the correct format remove declare module "iter" and prefix every symbol you wish to export with export declare, oh, and replace export = iter with export default iter. You can find additional info at https://github.com/Microsoft/TypeScript/wiki/Typings-for-npm-packages
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With