-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Specifying supported TypeScript versions #32166
Comments
I've been wanting this also. Maybe use
|
This already exists. If your package.json doesn't have a compatible TypeScript version, you'll see
We decided not to backport the |
@RyanCavanaugh this is great! However this does not seem to work for me. Steps to reproduce: $ npm install execa Manually edit (in "typesVersions": {
">=4": { "*": ["index.d.ts"] }
} Then using import 'execa' This creates no errors: $ tsc index.ts TypeScript |
Just to check while you have it set up, does this happen if |
If I rename With the original name, the
It does fallback to
It does not resolve |
Here's one thing you can try:
TypeScript versions earlier than 3.4 will load |
Thanks for this tip @rbuckton! It works but some issues with this approach could be:
More generally speaking this would be more of a workaround. Most TypeScript projects probably have a minimal supported TypeScript version, so it might be beneficial to have a "standard" way to specify it. This could also enable tools (linters, static analysis tools) to use it, in the same way that |
If we were to add a feature to disallow older versions of TypeScript, it wouldn't catch TS versions prior to the version where the feature was introduced. It's not pretty, but another workaround would be to introduce a type error that could provide some context to the users that the TS version they are using isn't supported. Something like: // notsupported.d.ts
type __Check<T extends ">= 3.6.1"> = T;
type __NotSupported = __Check<"This version of TypeScript">;
// error: Type '"This version of TypeScript"' does not satisfy the constraint '">= 3.6.1"'. |
Thanks @rbuckton! That does provide with a better error message, so this seems like the best workaround at the moment. Any feature related to this issue would indeed only work for users whose TS version is As a side note, I think the following might work as well, as a slight variation of the workaround above, maybe more explicit: "typesVersions": {
">=3.4.0-0": { "*": ["index.d.ts"] },
"*": { "*": ["notsupported.d.ts"] }
} |
Keep in mind that won't catch TypeScript 3.0 and earlier |
We are considering a mechanism to indicate an unsupported TypeScript version (with the caveat that earlier versions won't support this capability), but there is not enough time this iteration to implement it. The change might be something like this:
|
What happens if I do the opposite on my project? By default expose type declarations with a type error, and override it with the proper file for versions above |
This can has been getting kicked down the road for quite a while and it seems like this isn't enough of a problem in practice to warrant a capital-f Feature for it. It's pretty straightforward at this point to have a pre-minumum-tagged file with the content // @ts-expect-error
type RequiredTypeScriptVersion = "3.8"; which would be sufficient for people to figure out what's going on. |
I understand. Thanks @RyanCavanaugh for explaining the rational behind this decision and for providing a workaround. 👍 |
Has anyone implemented this approach? I can't seem to get it to officially work and wanted to see a working example if anyone has one. |
@smaye81 I implemented it in
|
Great thank you @IvanGoncharov ! |
Search Terms
version
minimal version
minimum version
typesVersions
Suggestion
Specifying the minimal TypeScript version supported by a project.
With
typesVersions
, fallbacks can be specified for earlier versions. But we cannot specify which earlier versions are not supported.Use Cases
Better error reporting for users using older TypeScript versions.
Examples
execa
types only support TypeScript>= 3.4
because of how thereadonly
keyword is used.There should be a way for us to specify this. One way would be to extend the
typesVersions
field to add this feature.Our users would then get a clear error message similar to the one produced by the
engines.node
field for Node.js versions. Instead at the moment, we get GitHub issues from users using older TypeScript versions.Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: