You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Provide a back-compat mechanism for bundled .d.ts files in package.json #22605
People are always excited to use new type system features in their programs or definition files.
However, if these developers are shipping a library with bundled type definitions, they can't use these features in an exposed way unless they are willing to force all TS consumers of the library to upgrade to a matching compiler version.
This leads to awkward trade-offs and end-user confusion when they upgrade eventually does happen.
There should be some way for library authors to say "Use this .d.ts file if you're on this version of TypeScript" so they can provide back-compat ranges. This could be based on semver ranges provided in package.json:
I would expect these files to be either hand-created, or generated through some downleveling process.
The model for DT doesn't apply here since people may need e.g. the runtime v12 of a library for bugfix/feature reasons but not be able to consume type syntax from that version
Most properties in package.json are camelCased, so I'd prefer "typesCompat" or "typesVersions" to "types-compat".
Path mappings need to be templated, as not all package definitions use ambient modules.
We don't need (and probably should disallow) a "*" version mapping as we still need to include "types" as the default for older versions of TypeScript.
We most likely cannot support this in older versions of TypeScript, only 3.1 (or which ever version would ship this feature) or better.
I specifically call out approximate path resolution semantics when importing from an ambient module (via declare module) vs. a non-ambient module.
I don't specifically call out using semver, though I agree it would be useful (especially in a package.json)
I also describe a proposed structure for DefinitelyTyped packages that could be used by types-publisher to automate package.json generation and package deployments.
Allow us to start leveraging /// <reference lib="..." /> in packages and remove empty forward-reference declarations for types like Iterator, AsyncIterator, IteratorResult, etc. (needed for node, es6-shim, core-js, etc.)
Allow us to support newer features such as conditional types and unique symbols in heavily used "trunk" type packages (such as node, moment, etc.).
Ryan Cavanaugh (@RyanCavanaugh) Seeing this I have an idea, I want to add the different language comment version in.d.ts file, and decide which version of the comment to use based on the environment variable local of tsconfig.json or vscode. Friendly tips when using vscode.
Activity
mhegazy commentedon Apr 5, 2018
RyanCavanaugh commentedon Apr 5, 2018
I would expect these files to be either hand-created, or generated through some downleveling process.
The model for DT doesn't apply here since people may need e.g. the runtime v12 of a library for bugfix/feature reasons but not be able to consume type syntax from that version
rbuckton commentedon Aug 15, 2018
A few comments:
"typesCompat"or"typesVersions"to"types-compat"."*"version mapping as we still need to include"types"as the default for older versions of TypeScript.rbuckton commentedon Aug 15, 2018
cc: Daniel Rosenwasser (@DanielRosenwasser) since we were discussing this feature this morning.
rbuckton commentedon Aug 15, 2018
I put together a proposal that is very similar to this, which also addresses my earlier comments.
The key differences are:
"typesVersion"instead of"types-compat"declare module) vs. a non-ambient module.I also describe a proposed structure for DefinitelyTyped packages that could be used by
types-publisherto automate package.json generation and package deployments.rbuckton commentedon Aug 15, 2018
I would also like to add that this would address a number of issues:
IteratorResultfrom an interface to a union type would break NodeJS types (as well ases6-shimandes6-collections)./// <reference lib="..." />in packages and remove empty forward-reference declarations for types likeIterator,AsyncIterator,IteratorResult, etc. (needed fornode,es6-shim,core-js, etc.)node,moment, etc.).AlexStacker commentedon Sep 19, 2018
Ryan Cavanaugh (@RyanCavanaugh) Seeing this I have an idea, I want to add the different language comment version in
.d.tsfile, and decide which version of the comment to use based on the environment variablelocalof tsconfig.json or vscode. Friendly tips when using vscode.