Skip to content
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

Support compatibility with previous TS versions for npm packages #41685

Closed
5 tasks done
Roaders opened this issue Nov 25, 2020 · 2 comments
Closed
5 tasks done

Support compatibility with previous TS versions for npm packages #41685

Roaders opened this issue Nov 25, 2020 · 2 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@Roaders
Copy link

Roaders commented Nov 25, 2020

Search Terms

compatibility previous typescript versions

Suggestion

Allow me to use the latest and greatest version of Typescript but allow me to specify the minimum TS version I want the emitted declaration files to be compatible with.

Use Cases

For example I might want to use the latest version of Typescript so that I could use the // @ts-expect-error in my tests but I might want my compiled package to be usable with TS 3.1. The emitted declaration files would not include this so would be compatible with 3.1

Examples

Latest and greatest features of TS could be used freely anywhere in the code. As soon as this results in incompatible types being emitted in the declaration files TS throws an error saying this is incompatible.
This would allow new features to be used within a function (where it will not affect the declaration files) but if you wanted to return an incompatible type you would be stopped.

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. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@MartinJohns
Copy link
Contributor

MartinJohns commented Nov 25, 2020

You can achieve this already by providing different .d.ts files for different TypeScript versions: https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#version-selection-with-typesversions

You can use the downlevel-dts tool by Nathan to create .d.ts files targeting older versions: https://github.com/sandersn/downlevel-dts

@RyanCavanaugh RyanCavanaugh added Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript labels Nov 25, 2020
@RyanCavanaugh
Copy link
Member

The current solution as described by @MartinJohns is as far as we intend to go in this area.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants