-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Feature: triple-slash directive to override "target" compiler option #35656
Open
5 tasks done
Labels
Comments
Related: #31035 |
@MartinJohns This issue is specifically only for #31035 isn't doable because it would include type resolution and other options that would lead to undefined requirements/behavior. |
RoyTinker
pushed a commit
to RoyTinker/TypeScript
that referenced
this issue
Dec 19, 2019
RoyTinker
pushed a commit
to RoyTinker/TypeScript
that referenced
this issue
Dec 19, 2019
Implement microsoft#35656
RoyTinker
pushed a commit
to RoyTinker/TypeScript
that referenced
this issue
Dec 19, 2019
Apologies - I'm trying to work on this in a fork and accidentally closed this issue via a commit message. |
RyanCavanaugh
added
In Discussion
Not yet reached consensus
Suggestion
An idea for TypeScript
labels
Jan 15, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Search Terms
tsconfig override per-file compilerOptions code emit
Suggestion
Add a triple-slash directive to override the
target
compiler option within specific .ts code files.Use Cases
With the final death of IE11 coming soon 🎈🎉🎊, my team and (I'm sure) many other teams are finally upgrading TS projects from
"target": "ES5"
to"ES6"
or beyond.What many of us will discover is that there can be subtle (or not-so-subtle) runtime differences between ES5 and newer syntactic equivalents--like true ES6
class
declarations and the ES5 equivalent function+prototype object.Our team has run into a problem where a library we still need to use calls class constructor functions using
apply
(notnew
) in its own implementation of inheritance/mixins - this throws aTypeError
at runtime (and no, it would be impossible to fix it without a prohibitive, major breaking change to the library).For reference, here's the relevant section of the ECMAScript standard: http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist, specifically
2. If F’s [[FunctionKind]] internal slot is "classConstructor", throw a TypeError exception.
.Because of this and other runtime differences that exist between different
target
values, it would be extremely helpful to allow overriding this setting per-file, for those files where problems are encountered that can't be fixed in any other way. Locating the override within source code makes sense, since codegen options that affect runtime have parallel concern with the source code itself.Alternatives?
The only alternatives I'm aware of are:
tsc
itself)Besides the first option, the alternatives all require separating the information "these files need to be ES5" from the content of those files. A triple-slash TS directive is the best option because it doesn't separate these parallel concerns.
TS Syntax
Using a triple-slash directive makes sense since this is a pattern that is already supported and used extensively. I suggest the following syntax:
This would also allow adding support for other compiler options in the future. However, it would only make sense to consider options that only affect code emit.
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: