Writing npm modules in TypeScript

前端 未结 7 500
醉话见心
醉话见心 2020-11-30 16:58

I am working on my first npm module. I briefly worked with TypeScript before and a big problem was that for many modules there were no definition files available. So I thoug

7条回答
  •  孤城傲影
    2020-11-30 17:45

    Here is a sample Node module written in TypeScript : https://github.com/basarat/ts-npm-module

    Here is a sample TypeScript project that uses this sample module https://github.com/basarat/ts-npm-module-consume

    Basically you need to :

    • compile with commonjs and declaration:true
    • generate a .d.ts file

    And then

    • Have your ide read the generated .d.ts.

    Atom-TypeScript just provides a nice workflow around this : https://github.com/TypeStrong/atom-typescript#packagejson-support

提交回复
热议问题