-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Enable a library to support an older compiler than the one used to build it #36207
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
Comments
We'd need some very strong evidence that |
Is We can take this approach, but it's a nontrivial work item. For a resuable toolchain, we'll have to document it and support it. |
Hmmm.. Is downlevel-dts only supported via CLI? What if we need to process buffers in memory? |
Is there a way for it to share the toolchain's compiler package as a peer dependency, rather than installing its own compiler version? |
Does downlevel-dts actually use the |
Will the .d.ts.map files be correct after this transform? |
@RyanCavanaugh this wold be a good use case for #16607 |
This is really quite frustrating, especially for Angular 8 (latest stable) applications locked to TypeScript 3.5, any dependencies which dutifully update to the latest (minor) TypeScript version and release a new lib with .d.ts files cause compilation issues and there's not a great deal the consumer can do about it other than lock down versions and stop updating. Case in point, three.js is no longer compatible with Angular! |
I realized there's another aspect to this problem: What happens if the exported API surface imports an incompatible type from an NPM dependency?
The simplest and best validation would be a side-by-side install of the oldest supported compiler version, which could run as a post-build step to detect any incompatibilities. But invoking two compiler versions will be costly, for both install times and execution times. Whereas the compiler should be able to perform this validation much more cheaply (considering that today the entire logic of Downleveling and validation are both needed to ensure compatibility, so it would make sense to integrate them into a single feature based on a single |
@jukibom You can force typescript 3.7.x on Angular 8. I have a situation where I have to support Angular 7 which does not have this option to do so. In your angular.json you can set: "cli": {
"warnings": {
"typescriptMismatch": false
}
} and use typescript 3.7.x. |
Search Terms
TS1086, getter, incompatible, 3.7
Use Case
Consider a library API like this:
If I compile this library using TypeScript 3.7, the resulting .d.ts file cannot be consumed by a project that uses TypeScript 3.5. The build will fail with this error:
Today, this error is considered "Working as Intended". For libraries that seek to maximize compatibility, this policy causes us to get stranded on a relatively old compiler release. 🤔
Note that the above source code is not using any new 3.7 language features. The class property getter syntax is the same in TS 3.5. In other words, backwards-compatible source code does NOT produce backwards-compatible .d.ts files.
Proposed change
Let's introduce a new option in tsconfig.json:
This would have two effects:
readonly title: string
instead ofget title(): string
for the above example)Where constructs can be transformed to equivalent older constructs (like what downlevel-dts does), that's nice to have. But it's NOT required. Reporting an error is perfectly acceptable, as long as backwards-compatible source code can produce backwards-compatible .d.ts files.
How far back do we want to be compatible? The
dtsCompatibilityVersion
option leaves this decision up to the library author, while enabling them to use the latest compiler engine.Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: