-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add target: "es2022"
#46291
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
Add target: "es2022"
#46291
Changes from 6 commits
5b7da72
63a65d7
c940acb
f28a433
c341cd7
e67d6e5
f384243
95b4ad8
5ebce82
2c91268
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
interface Array<T> { | ||
/** | ||
* Returns the item located at the specified index. | ||
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item. | ||
*/ | ||
at(index?: number): T; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we actually want to make this optional? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If leaving it with no parameter defaults to 0 and is valid, why not? Typescript is supposed to pick up on runtime errors, which this is not one There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be possible with optional parameter: // some function that omitting parameter actually makes sense
function foo(index?: number) {
// ...
const item = bar.indexAt(index);
// ...
} But I'm not sure how many people would do that. I'm happy to revert the last commit but I wonder what others think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any function would work like that for that matter. I think if it’s supported it should be kept like this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We have lots of precedent of not supporting everything under the sun just because it doesn't crash (e.g. #15122). If it's plausibly an error, we occasionally err on being restrictive. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Absolutely not. This situation is much different from the one above because that one doesn't make sense and has alternatives. This here has an alternative, which is passing an explicit 0, but when running .at() it would make sense for it to default to the first element in the array. This doesn't seem like another one of JS's quirks, but in fact very much intentional and should stay like this, unless a maintainer says otherwise There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't find any discussion from TC39 that says this is intentional, though. Happy to see one if exists. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry to complicate this merge late in the game, but I think we want WRT the idea of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two MS engineers prefer not to making it optional 👍 I'll add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think there was explicit discussion, but certainly as a member of TC39 it is my view that As a user, if I ever saw |
||
} | ||
|
||
interface ReadonlyArray<T> { | ||
/** | ||
* Returns the item located at the specified index. | ||
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item. | ||
*/ | ||
at(index?: number): T; | ||
} | ||
|
||
interface Int8Array { | ||
/** | ||
* Returns the item located at the specified index. | ||
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item. | ||
*/ | ||
at(index?: number): number; | ||
} | ||
|
||
interface Uint8Array { | ||
/** | ||
* Returns the item located at the specified index. | ||
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item. | ||
*/ | ||
at(index?: number): number; | ||
} | ||
|
||
interface Uint8ClampedArray { | ||
/** | ||
* Returns the item located at the specified index. | ||
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item. | ||
*/ | ||
at(index?: number): number; | ||
} | ||
|
||
interface Int16Array { | ||
/** | ||
* Returns the item located at the specified index. | ||
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item. | ||
*/ | ||
at(index?: number): number; | ||
} | ||
|
||
interface Uint16Array { | ||
/** | ||
* Returns the item located at the specified index. | ||
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item. | ||
*/ | ||
at(index?: number): number; | ||
} | ||
|
||
interface Int32Array { | ||
/** | ||
* Returns the item located at the specified index. | ||
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item. | ||
*/ | ||
at(index?: number): number; | ||
} | ||
|
||
interface Uint32Array { | ||
/** | ||
* Returns the item located at the specified index. | ||
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item. | ||
*/ | ||
at(index?: number): number; | ||
} | ||
|
||
interface Float32Array { | ||
/** | ||
* Returns the item located at the specified index. | ||
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item. | ||
*/ | ||
at(index?: number): number; | ||
} | ||
|
||
interface Float64Array { | ||
/** | ||
* Returns the item located at the specified index. | ||
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item. | ||
*/ | ||
at(index?: number): number; | ||
} | ||
|
||
interface BigInt64Array { | ||
/** | ||
* Returns the item located at the specified index. | ||
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item. | ||
*/ | ||
at(index?: number): number; | ||
} | ||
|
||
interface BigUint64Array { | ||
/** | ||
* Returns the item located at the specified index. | ||
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item. | ||
*/ | ||
at(index?: number): number; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/// <reference lib="es2021" /> | ||
/// <reference lib="es2022.array" /> | ||
/// <reference lib="es2022.object" /> | ||
/// <reference lib="es2022.string" /> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/// <reference lib="es2022" /> | ||
/// <reference lib="dom" /> | ||
/// <reference lib="webworker.importscripts" /> | ||
/// <reference lib="scripthost" /> | ||
/// <reference lib="dom.iterable" /> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
interface Object { | ||
/** | ||
* Determines whether an object has a property with the specified name. | ||
* @param o An object. | ||
* @param v A property name. | ||
*/ | ||
hasOwn(o: object, v: PropertyKey): boolean; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
interface String { | ||
/** | ||
* Returns a new String consisting of the single UTF-16 code unit located at the specified index. | ||
* @param index The zero-based index of the desired code unit. A negative index will count back from the last item. | ||
*/ | ||
at(index?: number): string; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
/// <reference lib="es2021" /> | ||
/// <reference lib="es2022" /> | ||
/// <reference lib="esnext.intl" /> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//// [callChainWithSuper.ts] | ||
// GH#34952 | ||
class Base { method?() {} } | ||
class Derived extends Base { | ||
method1() { return super.method?.(); } | ||
method2() { return super["method"]?.(); } | ||
} | ||
|
||
//// [callChainWithSuper.js] | ||
"use strict"; | ||
// GH#34952 | ||
class Base { | ||
method() { } | ||
} | ||
class Derived extends Base { | ||
method1() { return super.method?.(); } | ||
method2() { return super["method"]?.(); } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If ES2022 does not contain new syntax, should we skip
ContainsES2022
flag (or setContainsES2022
=ContainsES2021
) to save the bitflag?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are (notably class private fields), but just not here yet AFAIK.