-
Notifications
You must be signed in to change notification settings - Fork 12.8k
What is the correct way to write a .d.ts file for a node module, which is referenced in package.json? #8335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
change your .d.ts file to be a module (i.e. a top level import or export), so it would look like: import nock = require('nock');
declare namespace parallelNock {
export function release():void;
}
declare function parallelNock (host: string, options?: any): any;
export = parallelNock; |
we have some documentation about exposing types in npm at: http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html that could definitely be better though. we are working on updating the typing acquisition story, so i will leave this issue open until that is done. |
for completeness, here is the guide for writing definition files: http://www.typescriptlang.org/docs/handbook/writing-declaration-files.html |
Oh, thank you for the valuable input, @mhegazy. About documentation... well, I know, theres always not enough time... Anyway, what you already have is already very valuable. |
correct. and the name of the module that users import with is the name of the package. The logic should follow the same node package logic, i.e. index.d.ts would do, otherwise you need to specify "typings" entry, like you do with "main". so your package can look like
or
|
I did next:
|
In case you use typings, you should rather let it do that for you. You can use
to add a dependency to a local type definition (refer to typings.json or index.d.ts) or you create a github-repository and fetch it from there. |
react markdown use in Typescript.
markdown.d.ts:
Anyone konws how to resolve it? |
use: import Markdown from 'react-markdown'; |
Thank you ,It doesn't report an error,but markdown file doesn't render . |
Trying to follow the tips given here, but not quite getting any traction. Thoughts? https://stackoverflow.com/questions/57032253/providing-an-index-d-ts-file-for-canonical-json |
Addressing moneybutton#137 (comment) with the solution from microsoft/TypeScript#8335 (comment)
Hi @mhegazy, I am a noob programmer. I need to know how did you find this information or and link to the docs? Any help is much appreciated. |
So, i am working on a small module written in JS, but I want to make it easy to use that module in TypeScript as well. It adds a wrapper with some additional functionality around an existing JS module.
In my module path i have package.json with:
index.js is a very simple module, exporting just a function:
And index.d.ts is:
, I get:
The text was updated successfully, but these errors were encountered: