When using Node module resolution in TypeScript 3.1, when TypeScript cracks open a package.json
file to figure out which files it needs to read, it first looks at a new field called typesVersions
.A package.json
with a typesVersions
field might look like this:
So in the above example, if we’re importing from "package-name"
, we’ll try to resolve from […]/node_modules/package-name/ts3.1/index.d.ts
(and other relevant paths) when running in TypeScript 3.1.If we import from package-name/foo
, we’ll try to look for […]/node_modules/package-name/ts3.1/foo.d.ts
and .
The way that TypeScript decides on whether a version of the compiler & language matches is by using Node’s .
Multiple fields
Since ranges have the potential to overlap, determining which redirect applies is order-specific.That means in the above example, even though both the >=3.2
and the matchers support TypeScript 3.2 and above, reversing the order could have different behavior, so the above sample would not be equivalent to the following.