microsoft / dts-gen

dts-gen creates starter TypeScript definition files for any module or library.
MIT License
2.43k stars 102 forks source link

dts-gen vs tsc -d, --declaration #12

Open huashiyiqike opened 7 years ago

huashiyiqike commented 7 years ago

The two commands seem the same. What are the differences and which one should I use?

RyanCavanaugh commented 7 years ago

dts-gen works differently from TypeScript, Flowtype, Tern, etc. because it simply examines the objects as they appear at runtime, rather than needing the source code that creates the object. This means no matter how the object was written, anything, including native objects, can be given an inferred shape.

This trade-off comes with a price -- you'll see a lot of anys in function parameters and return types. You may also see properties that are not intended for public use. dts-gen is meant to be a starting point for writing a high-quality definition file.

huashiyiqike commented 7 years ago

Now I get it, tsc won't generate header for normal js packages.

tsc -d velocity-react --allowJs error TS5053: Option 'allowJs' cannot be specified with option 'declaration'.

Yet, is there a way to generate type definitions with dts-gen for packages locally installed in node_modules directory? Seems that is not supported.

FDiskas commented 6 years ago

@huashiyiqike use npm | yarn link