Description
Search Terms
dts-gen
third party modules
fallback
typings
modules without typings
Suggestion
One of the biggest concerns I've heard from new users using TypeScript is dealing with libraries that have no typings provided (neither in the library itself nor in DefinitelyTyped). In a strict
TS environment or with noImplicitAny: true
, TypeScript will complain about a library you import that has no associated typings definition.
Your options at this point are to provide your own typings file in a local typings
folder, or use dts-gen
to generate one for you.
Personally, I find this to be a useful exercise but newer users get tripped up on it and frequently cite it as one of the harder parts about TS adoption.
I had considered creating a library (similar to https://github.com/tamayika/types-local) that would use dts-gen
to automatically put index.d.ts
files inside of libraries within your node_modules
folder that have no associated typings, provided you've imported the library in your code. This would probably end up being gross and an npm anti-pattern.
Instead, it would be nice if the compiler could do this for us. If you have imported code w/o typings, the TS compiler could use dts-gen
to generate typings (which obviously are imperfect) which would allow folks to proceed without worrying immediately about whether the library has typings.
Maybe a flag called dtsGenFallback
under compilerOptions
could do this?
Use Cases
Described above
Examples
Described above
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript / JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. new expression-level syntax)