GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add `target: "es2022"` by saschanaz · Pull Request #46291 · microsoft/TypeScript

Conversation

@saschanaz

@saschanaz Kagami Sascha Rosylight (saschanaz) commented Oct 10, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes #44571, fixes #45512

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

dnalborczyk, ntnyq, styfle, DTrombett, Naddiseo, and mix4242 reacted with thumbs up emoji dnalborczyk and styfle reacted with hooray emoji dnalborczyk and styfle reacted with rocket emoji
All reactions
  • 👍 6 reactions
  • 🎉 2 reactions
  • 🚀 2 reactions
Kagami Sascha Rosylight (saschanaz) added 3 commits October 10, 2021 13:24
@saschanaz
Add target: "es2022"
5b7da72
@saschanaz
Add Object.hasOwn
63a65d7
@saschanaz
formatToParts is es2018
c940acb
@typescript-bot

TypeScript Bot (typescript-bot) commented Oct 10, 2021

Copy link
Copy Markdown
Contributor

Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping Sheetal Nandi (@sheetalkamat), Andrew Casey (@amcasey), Matt Bierner (@mjbvz), Mine Starks (@minestarks) for you. Feel free to loop in other consumers/maintainers if necessary

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot TypeScript Bot (typescript-bot) added the For Backlog Bug PRs that fix a backlog bug label Oct 10, 2021
@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Oct 11, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

While it's not ideal that it's not in the beta, this probably should go in 4.5.

dnalborczyk reacted with thumbs up emoji dnalborczyk reacted with rocket emoji
All reactions
  • 👍 1 reaction
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@amcasey

Andrew Casey (amcasey) commented Oct 11, 2021

Copy link
Copy Markdown
Member

Protocol change looks fine 👍

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser) requested review from Andrew Branch (andrewbranch) and Ron Buckton (rbuckton) October 14, 2021 19:15
ImRodry
Rodrigo Leitão (ImRodry) reviewed Oct 26, 2021
View reviewed changes
Comment thread src/lib/es2022.array.d.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

Kagami Sascha Rosylight (saschanaz) added 3 commits October 26, 2021 23:52
@saschanaz
Merge remote-tracking branch 'upstream/main' into es2022
f28a433
@saschanaz
ref update
c341cd7
@saschanaz
optional parameter
e67d6e5
DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser) reviewed Oct 28, 2021
View reviewed changes
Comment thread src/lib/es2022.array.d.ts Outdated
* 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;

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Oct 28, 2021

Copy link
Copy Markdown
Member

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.

Do we actually want to make this optional? slice() makes sense because it's common to copy an entire array, I don't know if allowing forgotten arguments is worth supporting the idiom of peeking at the front.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ImRodry Rodrigo Leitão (ImRodry) Oct 28, 2021

Copy link
Copy Markdown

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 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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@saschanaz Kagami Sascha Rosylight (saschanaz) Oct 28, 2021

Copy link
Copy Markdown
Contributor Author

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.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ImRodry Rodrigo Leitão (ImRodry) Oct 28, 2021

Copy link
Copy Markdown

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.

Any function would work like that for that matter. I think if it’s supported it should be kept like this

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Oct 28, 2021

Copy link
Copy Markdown
Member

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.

Typescript is supposed to pick up on runtime errors, which this is not one

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

saschanaz reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@ImRodry Rodrigo Leitão (ImRodry) Oct 28, 2021

Copy link
Copy Markdown

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.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@saschanaz Kagami Sascha Rosylight (saschanaz) Oct 28, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

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.

I can't find any discussion from TC39 that says this is intentional, though. Happy to see one if exists.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@orta Orta Therox (orta) Oct 28, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

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.

Sorry to complicate this merge late in the game, but I think we want at(index: number): T | undefined; - #45512 (comment)

WRT the idea of index?: number vs index: number I don't personally have a strong opinion either way, but if forced I think we should drop the ? and go with index: number because I think it matches the intention of at(0) which feels different to at(undefined)/at() because the omission doesn't really communicate the same thing

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

saschanaz and DanielRosenwasser reacted with thumbs up emoji ImRodry reacted with confused emoji
All reactions
  • 👍 2 reactions
  • 😕 1 reaction

@saschanaz Kagami Sascha Rosylight (saschanaz) Oct 28, 2021

Copy link
Copy Markdown
Contributor Author

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.

Two MS engineers prefer not to making it optional 👍

I'll add | undefined and the newly accepted Error Cause proposal tomorrow (unless anyone prefers to making it a separate PR).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bakkot Kevin Gibbons (bakkot) Nov 5, 2021

Copy link
Copy Markdown
Contributor

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.

I can't find any discussion from TC39 that says this is intentional, though. Happy to see one if exists.

I don't think there was explicit discussion, but certainly as a member of TC39 it is my view that at coerces undefined to 0 only because everything similar in the language works that way, not because we actually think people should pass undefined or omit the parameter. By analogy, you can also call it with '0', but that doesn't mean | '0' belongs in the signature.

As a user, if I ever saw at being called with undefined or without an argument, I'd assume that was a bug.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

saschanaz, darrylnoakes, danielrentz, Yogu, and wchargin reacted with thumbs up emoji SancheZz reacted with thumbs down emoji
All reactions
  • 👍 5 reactions
  • 👎 1 reaction
Kagami Sascha Rosylight (saschanaz) and others added 4 commits October 29, 2021 02:21
@saschanaz
Revert "optional parameter"
f384243
This reverts commit e67d6e5.
@saschanaz
undefined
95b4ad8
@saschanaz
error cause
5ebce82
@orta
Lint fix
2c91268
@orta Orta Therox (orta) mentioned this pull request Oct 29, 2021
fix(Node): Array.at's index parameter is optional DefinitelyTyped/DefinitelyTyped#56782
Closed
6 of 8 tasks
@andrewbranch Andrew Branch (andrewbranch) added this to the TypeScript 4.6.0 milestone Nov 2, 2021
orta
Orta Therox (orta) approved these changes Nov 4, 2021
View reviewed changes
sandersn
Nathan Shively-Sanders (sandersn) approved these changes Nov 4, 2021
View reviewed changes
@andrewbranch
Andrew Branch (andrewbranch) merged commit ae582a2 into microsoft:main Nov 4, 2021
@saschanaz
Kagami Sascha Rosylight (saschanaz) deleted the es2022 branch November 4, 2021 18:23
@ImRodry Rodrigo Leitão (ImRodry) mentioned this pull request Nov 4, 2021
types(At): make index a required parameter discordjs/collection#51
Merged
This was referenced Nov 5, 2021
Add Error causes #45749
Closed
TC39 proposal - Error.cause property #45167
Closed
@BasixKOR Sung Jeon (BasixKOR) mentioned this pull request Nov 5, 2021
Path to stage 4! tc39/proposal-error-cause#2
Closed
24 of 28 tasks
Jack-Works
Jack Works (Jack-Works) reviewed Dec 3, 2021
View reviewed changes
Comment thread src/compiler/types.ts
AssertTypeScript = ContainsTypeScript,
AssertJsx = ContainsJsx,
AssertESNext = ContainsESNext,
AssertES2022 = ContainsES2022,

@Jack-Works Jack Works (Jack-Works) Dec 3, 2021

Copy link
Copy Markdown
Contributor

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 set ContainsES2022 = ContainsES2021) to save the bitflag?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@saschanaz Kagami Sascha Rosylight (saschanaz) Dec 3, 2021

Copy link
Copy Markdown
Contributor Author

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tychenjiajun

Jiajun Chen (tychenjiajun) commented Dec 9, 2021

Copy link
Copy Markdown
const selections = [
    { foo: 1 }, { bar: 2 }
] as const;

type A = typeof selections[0];
type B = typeof selections.at(-2);

Will A and B be the same type?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@PabloLION

Pablo LION (PabloLION) commented Dec 11, 2021

Copy link
Copy Markdown

Hi team. In playground v4.5.2, Array.prototype.at is still not supported. How should I configure TS to suppress the error?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@saschanaz

Kagami Sascha Rosylight (saschanaz) commented Dec 11, 2021

Copy link
Copy Markdown
Contributor Author

This didn't enter 4.5, so you should wait for 4.6 or use nightly.

noinkling reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rbuckton

Ron Buckton (rbuckton) commented Dec 13, 2021

Copy link
Copy Markdown
Contributor

ES2022 contains private fields and static {}.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@saschanaz

Kagami Sascha Rosylight (saschanaz) commented Dec 13, 2021

Copy link
Copy Markdown
Contributor Author

Yup, that's #47018

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@PabloLION

Pablo LION (PabloLION) commented Dec 14, 2021

Copy link
Copy Markdown

Thanks for the clarification

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@DevDengChao 邓超 (DevDengChao) mentioned this pull request Dec 16, 2021
Targeting ES2022 in tsconfig.json SchemaStore/schemastore#1976
Merged
Martin Probst (mprobst) pushed a commit to mprobst/TypeScript that referenced this pull request Jan 10, 2022
@saschanaz @orta @mprobst
Add target: "es2022" (microsoft#46291)
17b01bc
* Add `target: "es2022"`

* Add Object.hasOwn

* formatToParts is es2018

* ref update

* optional parameter

* Revert "optional parameter"

This reverts commit e67d6e5.

* undefined

* error cause

* Lint fix

Co-authored-by: Orta <[email protected]>
This was referenced Feb 1, 2022
Add at method #40697
Closed
Add support of Item method (stage 3) #40695
Closed
@Soul-Master Soul_Master (Soul-Master) mentioned this pull request Feb 3, 2022
TypeScript 4.6 Iteration Plan #46858
Closed
@bennypowers

Benny Powers (bennypowers) commented Mar 6, 2022

Copy link
Copy Markdown

When useDefineForClassFields is false, es2022 transforms simple static class fields into class static init blocks. This is a problem for users that need useDefineForClassFields (lit requires this). As well, class fields and class private members are widely supported, where class static init blocks are not. Class fields have smaller bytecounts than transformed output, and are easier to read. I understand that the code is equivalent on an engine which supports static class blocks, but this presents a serious problem for some users, and I think TSC should provide an escape hatch.

Don't get me wrong, I think static blocks are super cool, and I'm looking forward to using them, but many users will want to use es2022 to get native private class members, which are widely supported, but they'll get stuck with static init blocks that they didn't write in source - a syntax error in most toolchains and on apple's monopoly engine webkit

https://www.typescriptlang.org/play?target=9#code/MYGwhgzhAECC0G8BQ1XQgFzBglsaY0AvNAORikDcSAvkA

input:

class A {
  static a = 'a';
}

output:

"use strict";
class A {
    static { this.a = 'a'; }
}

In my case, I have library sources that use decorators and need to be compiled with set semantics, but I also want them to have untranspiled private fields, which are widely supported.

Thank you for considering this case.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@saschanaz

Kagami Sascha Rosylight (saschanaz) commented Mar 7, 2022

Copy link
Copy Markdown
Contributor Author

That looks very much like a bug, please file it as a separate issue. Thanks

bennypowers reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bennypowers Benny Powers (bennypowers) mentioned this pull request Mar 7, 2022
es2022 transpiles class fields to static init blocks #48145
Open
@bennypowers

Benny Powers (bennypowers) commented Mar 7, 2022

Copy link
Copy Markdown

That looks very much like a bug, please file it as a separate issue. Thanks

#48145

saschanaz reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lediur Derrick Liu (lediur) mentioned this pull request Mar 10, 2022
lib.es2022: hasOwn appears to be defined on Object prototype rather than on constructor #48206
Closed
Benny Powers (bennypowers) added a commit to apollo-elements/apollo-elements that referenced this pull request Mar 29, 2022
@bennypowers
fix: compile away class static blocks
51b7df5
See microsoft/TypeScript#46291 (comment)
@bennypowers Benny Powers (bennypowers) mentioned this pull request Mar 29, 2022
fix: compile away class static blocks apollo-elements/apollo-elements#243
Merged
Benny Powers (bennypowers) added a commit to apollo-elements/apollo-elements that referenced this pull request Mar 29, 2022
@bennypowers
fix: compile away class static blocks
1bb1428
See microsoft/TypeScript#46291 (comment)
This was referenced Jun 16, 2022
Add .findLast() and .findLastIndex() bloomberg/TypeScript#69
Merged
Add Array.prototype.findLast() and Array.prototype.findLastIndex() #49636
Merged
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) DanielRosenwasser left review comments
@sandersn Nathan Shively-Sanders (sandersn) sandersn approved these changes
@andrewbranch Andrew Branch (andrewbranch) Awaiting requested review from andrewbranch
@rbuckton Ron Buckton (rbuckton) Awaiting requested review from rbuckton
+4 more reviewers
@bakkot Kevin Gibbons (bakkot) bakkot left review comments
@Jack-Works Jack Works (Jack-Works) Jack-Works left review comments
@ImRodry Rodrigo Leitão (ImRodry) ImRodry left review comments
@orta Orta Therox (orta) orta approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

PR Backlog
Archived in project

Milestone

TypeScript 4.6.0

Development

Successfully merging this pull request may close these issues.

Support Array.prototype.at Add target: es2022

Uh oh!

There was an error while loading. Please reload this page.

14 participants

@saschanaz @typescript-bot @DanielRosenwasser @amcasey @tychenjiajun @PabloLION @rbuckton @bennypowers @orta @sandersn @bakkot @Jack-Works @ImRodry @andrewbranch
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.