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 — Enum unification and improvements by ahejlsberg · Pull Request #50528 · microsoft/TypeScript

Conversation

@ahejlsberg

@ahejlsberg Anders Hejlsberg (ahejlsberg) commented Aug 29, 2022 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

Since #9407 TypeScript has had two kinds of enum types: Numeric enum types and literal enum types (also known as union enum types). Numeric enum types have permitted enum members to have computed values, but not literal types; whereas literal enum types have required members to be declared using simple numeric or string literals only. The distinction between these two kinds of enums is subtle and has been the source of a fair amount of confusion over time.

With this PR we unify the two kinds into a single hybrid that incorporates the best of both worlds. Specifically, enums are always represented as unions of their member types, member values may be computed by constant or non-constant expressions, and members with constant values are given literal types. The PR only affects type checking of enums. There are no changes to the emitted code (except for better inlining of constant expressions in some cases).

An enum declaration now declares a type representing the entire enum and types representing each member (similar to literal enum types). For example,

enum E {
    A = 10 * 10,  // Numeric literal enum member
    B = "foo",    // String literal enum member
    C = bar(42)   // Opaque computed enum member
}

declares a type E and types E.A, E.B, and E.C, where E is the union E.A | E.B | E.C.

An enum member has a literal enum type when it is initialized by a constant expression or when it has no initializer and is given an auto-incremented numeric value. In the example above, E.A and E.B denote enum literal types with values 100 and "foo" respectively.

An enum member has a unique and opaque enum member type when it is initialized by a non-constant expression. Non-constant initializer expressions must be assignable to type number and are not permitted in const enum declarations. In the example above, E.C denotes a unique enum member type representing the value computed by the non-constant initializer expression. This unique type is assignable to type number, but otherwise incompatible with other types.

An expression is considered a constant expression if it is

  • a number or string literal,
  • a unary +, -, or ~ applied to a numeric constant expression,
  • a binary +, -, *, /, %, **, <<, >>, >>>, |, &, ^ applied to two numeric constant expressions,
  • a binary + applied to two constant expressions whereof at least one is a string,
  • a template expression where each substitution expression is a constant expression,
  • a parenthesized constant expression,
  • a dotted name (e.g. x.y.z) that references a const variable with a constant expression initializer and no type annotation,
  • a dotted name that references an enum member with an enum literal type, or
  • a dotted name indexed by a string literal (e.g. x.y["z"]) that references an enum member with an enum literal type.

Note that constant expressions are not permitted to make forward references--any value referenced by a constant expression must have been previously declared.

Some examples:

const BaseValue = 10;
const Prefix = "/data";
const enum Values {
    First = BaseValue,  // 10
    Second,             // 11
    Third               // 12
}
const enum Routes {
    Parts = `${prefix}/parts`,       // "/data/parts"
    Invoices = `${prefix}/invoices`  // "/data/invoices"
}

NOTE: This PR is technically a breaking change because checking of the new unified enum types is stricter than the old numeric enum types.

Fixes #27976.
Fixes #35875.
Fixes #40793.
Fixes #43902.

Sorry, something went wrong.

Uh oh!

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

jackmcpickle, Vishtar, std4453, alexrock, jakebailey, RyanGrieb, t7yang, swese44, kirillgroshkov, tonivj5, and 70 more reacted with thumbs up emoji dead-claudia, lin72h, lukeramsden, k4b7, kwiatek-kainos, sokcuri, fyko, nicojs, extradosages, amelinium23, and 8 more reacted with hooray emoji dartess, ppluuums-jp, cockscomb, patricio-hondagneu-simplisafe, uriannrima, Quentame, albohlabs, Sajjon, cwrllab, daniele-orlando, and 2 more reacted with heart emoji iamravisingh, ExE-Boss, 1yzz, yukinotech, Sajjon, and cwrllab reacted with rocket emoji service-paradis, lukeramsden, amitbeck, natalia-lafever, purlingstream, 1yzz, unao, Sajjon, and cwrllab reacted with eyes emoji
All reactions
  • 👍 80 reactions
  • 🎉 18 reactions
  • ❤️ 12 reactions
  • 🚀 6 reactions
  • 👀 9 reactions
Anders Hejlsberg (ahejlsberg) added 4 commits July 21, 2022 06:08
@ahejlsberg
Fix enum classification and evaluation
6ec5053
@ahejlsberg
References in literal enums must be to other enum members
44a2b87
@ahejlsberg
Accept new baselines
66df808
@ahejlsberg
Merge branch 'main' into enumImprovements
50a952b
@typescript-bot TypeScript Bot (typescript-bot) assigned Anders Hejlsberg (ahejlsberg) Aug 29, 2022
@typescript-bot TypeScript Bot (typescript-bot) added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Aug 29, 2022
@ahejlsberg
Anders Hejlsberg (ahejlsberg) requested a review from Ryan Cavanaugh (RyanCavanaugh) August 29, 2022 22:16
@RyanCavanaugh

Ryan Cavanaugh (RyanCavanaugh) commented Aug 29, 2022

Copy link
Copy Markdown
Member

TypeScript Bot (@typescript-bot) pack this

All reactions

Sorry, something went wrong.

Uh oh!

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

@typescript-bot

TypeScript Bot (typescript-bot) commented Aug 29, 2022 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Heya Ryan Cavanaugh (@RyanCavanaugh), I've started to run the tarball bundle task on this PR at 50a952b. You can monitor the build here.

All reactions

Sorry, something went wrong.

Uh oh!

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

@ahejlsberg

Anders Hejlsberg (ahejlsberg) commented Aug 29, 2022

Copy link
Copy Markdown
Member Author

TypeScript Bot (@typescript-bot) test this
TypeScript Bot (@typescript-bot) user test this inline
TypeScript Bot (@typescript-bot) run dt
TypeScript Bot (@typescript-bot) perf test faster

All reactions

Sorry, something went wrong.

Uh oh!

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

@typescript-bot

TypeScript Bot (typescript-bot) commented Aug 29, 2022 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the extended test suite on this PR at 50a952b. You can monitor the build here.

All reactions

Sorry, something went wrong.

Uh oh!

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

@typescript-bot

TypeScript Bot (typescript-bot) commented Aug 29, 2022 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the abridged perf test suite on this PR at 50a952b. You can monitor the build here.

Update: The results are in!

All reactions

Sorry, something went wrong.

Uh oh!

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

@typescript-bot

TypeScript Bot (typescript-bot) commented Aug 29, 2022 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the parallelized Definitely Typed test suite on this PR at 50a952b. You can monitor the build here.

All reactions

Sorry, something went wrong.

Uh oh!

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

@typescript-bot

TypeScript Bot (typescript-bot) commented Aug 29, 2022 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the diff-based user code test suite on this PR at 50a952b. You can monitor the build here.

Update: The results are in!

All reactions

Sorry, something went wrong.

Uh oh!

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

@typescript-bot

TypeScript Bot (typescript-bot) commented Aug 29, 2022

Copy link
Copy Markdown
Contributor

Anders Hejlsberg (@ahejlsberg)
The results of the perf run you requested are in!

Here they are:

Comparison Report - main..50528

Metric main 50528 Delta Best Worst
Angular - node (v14.15.1, x64)
Memory used 338,727k (± 0.00%) 338,717k (± 0.01%) -9k (- 0.00%) 338,668k 338,757k
Parse Time 2.08s (± 0.70%) 2.09s (± 0.93%) +0.02s (+ 0.82%) 2.06s 2.15s
Bind Time 0.80s (± 0.62%) 0.80s (± 0.75%) +0.00s (+ 0.00%) 0.79s 0.81s
Check Time 5.82s (± 0.58%) 5.83s (± 0.27%) +0.01s (+ 0.14%) 5.79s 5.87s
Emit Time 6.18s (± 0.49%) 6.22s (± 0.72%) +0.04s (+ 0.58%) 6.16s 6.37s
Total Time 14.87s (± 0.27%) 14.93s (± 0.40%) +0.06s (+ 0.41%) 14.85s 15.11s
Compiler-Unions - node (v14.15.1, x64)
Memory used 192,654k (± 0.02%) 192,983k (± 0.37%) +329k (+ 0.17%) 192,631k 195,896k
Parse Time 0.86s (± 0.52%) 0.85s (± 0.87%) -0.01s (- 0.58%) 0.84s 0.87s
Bind Time 0.49s (± 0.75%) 0.49s (± 0.82%) +0.00s (+ 0.62%) 0.48s 0.50s
Check Time 6.70s (± 0.55%) 6.73s (± 0.69%) +0.03s (+ 0.43%) 6.64s 6.85s
Emit Time 2.41s (± 1.02%) 2.40s (± 0.72%) -0.01s (- 0.54%) 2.35s 2.43s
Total Time 10.46s (± 0.45%) 10.47s (± 0.51%) +0.02s (+ 0.16%) 10.35s 10.62s
Monaco - node (v14.15.1, x64)
Memory used 326,505k (± 0.01%) 326,536k (± 0.00%) +31k (+ 0.01%) 326,510k 326,581k
Parse Time 1.57s (± 0.59%) 1.60s (± 1.50%) +0.03s (+ 1.65%) 1.57s 1.69s
Bind Time 0.73s (± 0.85%) 0.73s (± 0.68%) -0.00s (- 0.41%) 0.72s 0.74s
Check Time 5.73s (± 0.51%) 5.78s (± 0.51%) +0.05s (+ 0.86%) 5.73s 5.85s
Emit Time 3.35s (± 0.61%) 3.35s (± 0.67%) -0.00s (- 0.12%) 3.30s 3.40s
Total Time 11.39s (± 0.42%) 11.45s (± 0.44%) +0.06s (+ 0.55%) 11.35s 11.55s
TFS - node (v14.15.1, x64)
Memory used 289,645k (± 0.00%) 289,648k (± 0.01%) +3k (+ 0.00%) 289,614k 289,687k
Parse Time 1.31s (± 0.83%) 1.31s (± 0.80%) +0.01s (+ 0.38%) 1.30s 1.34s
Bind Time 0.78s (± 2.29%) 0.80s (± 0.75%) +0.01s (+ 1.40%) 0.78s 0.81s
Check Time 5.36s (± 0.54%) 5.35s (± 0.62%) -0.01s (- 0.24%) 5.27s 5.44s
Emit Time 3.60s (± 0.77%) 3.57s (± 0.76%) -0.03s (- 0.75%) 3.51s 3.63s
Total Time 11.05s (± 0.38%) 11.03s (± 0.59%) -0.03s (- 0.25%) 10.87s 11.20s
material-ui - node (v14.15.1, x64)
Memory used 438,087k (± 0.06%) 438,212k (± 0.00%) +125k (+ 0.03%) 438,180k 438,251k
Parse Time 1.86s (± 0.59%) 1.87s (± 0.59%) +0.01s (+ 0.38%) 1.84s 1.89s
Bind Time 0.59s (± 0.62%) 0.59s (± 1.10%) +0.00s (+ 0.34%) 0.58s 0.61s
Check Time 13.06s (± 0.95%) 12.92s (± 0.81%) -0.14s (- 1.06%) 12.72s 13.15s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.51s (± 0.81%) 15.38s (± 0.72%) -0.13s (- 0.83%) 15.16s 15.62s
xstate - node (v14.15.1, x64)
Memory used 547,388k (± 0.00%) 547,403k (± 0.00%) +15k (+ 0.00%) 547,362k 547,442k
Parse Time 2.60s (± 0.45%) 2.62s (± 0.47%) +0.02s (+ 0.73%) 2.60s 2.65s
Bind Time 0.97s (± 0.70%) 0.98s (± 0.68%) +0.01s (+ 0.62%) 0.97s 0.99s
Check Time 1.54s (± 0.62%) 1.54s (± 0.42%) -0.00s (- 0.13%) 1.53s 1.55s
Emit Time 0.07s (± 4.13%) 0.07s (± 3.14%) -0.00s (- 1.39%) 0.07s 0.08s
Total Time 5.20s (± 0.42%) 5.22s (± 0.21%) +0.02s (+ 0.38%) 5.19s 5.24s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-210-generic
Architecturex64
Available Memory16 GB
Available Memory15 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v14.15.1, x64)
  • xstate - node (v14.15.1, x64)
Benchmark Name Iterations
Current 50528 10
Baseline main 10

Developer Information:

Download Benchmark

All reactions

Sorry, something went wrong.

Uh oh!

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

@typescript-bot

TypeScript Bot (typescript-bot) commented Aug 29, 2022

Copy link
Copy Markdown
Contributor

Anders Hejlsberg (@ahejlsberg) Here are the results of running the user test suite comparing main and refs/pull/50528/merge:

Everything looks good!

All reactions

Sorry, something went wrong.

Uh oh!

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

@typescript-bot

TypeScript Bot (typescript-bot) commented Aug 29, 2022

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've run the RWC suite on this PR - assuming you're on the TS core team, you can view the resulting diff here.

All reactions

Sorry, something went wrong.

Uh oh!

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

@typescript-bot

TypeScript Bot (typescript-bot) commented Aug 29, 2022 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Hey Ryan Cavanaugh (@RyanCavanaugh), I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/133037/artifacts?artifactName=tgz&fileId=3F948668C1BD8758CB1C8E59919B3D6E945DCF3815094A729B98FCE15A366B7E02&fileName=/typescript-4.9.0-insiders.20220829.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/[email protected]".;

All reactions

Sorry, something went wrong.

Uh oh!

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

@zendesk-olgaczarnecka Olga Czarnecka (zendesk-olgaczarnecka) mentioned this pull request Sep 30, 2022
Enable constants as computed values for string enums #40793
Closed
Anders Hejlsberg (ahejlsberg) added 5 commits October 12, 2022 14:02
@ahejlsberg
Merge branch 'main' into enumImprovements
7eaef66
@ahejlsberg
Unify enum types + template literal constant expressions
95f512e
@ahejlsberg
Accept new baselines
c1a176c
@ahejlsberg
Fix fourslash tests
9b1dbea
@ahejlsberg
Fix new compiler errors
3f66f6c
@ahejlsberg

Anders Hejlsberg (ahejlsberg) commented Oct 17, 2022

Copy link
Copy Markdown
Member Author

TypeScript Bot (@typescript-bot) test this
TypeScript Bot (@typescript-bot) user test this inline
TypeScript Bot (@typescript-bot) run dt
TypeScript Bot (@typescript-bot) perf test faster
TypeScript Bot (@typescript-bot) test top100

All reactions

Sorry, something went wrong.

Uh oh!

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

@typescript-bot

TypeScript Bot (typescript-bot) commented Oct 17, 2022 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the diff-based top-repos suite on this PR at 3f66f6c. You can monitor the build here.

Update: The results are in!

All reactions

Sorry, something went wrong.

Uh oh!

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

@typescript-bot

TypeScript Bot (typescript-bot) commented Oct 17, 2022 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the diff-based user code test suite on this PR at 3f66f6c. You can monitor the build here.

Update: The results are in!

All reactions

Sorry, something went wrong.

Uh oh!

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

@typescript-bot

TypeScript Bot (typescript-bot) commented Oct 17, 2022 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the abridged perf test suite on this PR at 3f66f6c. You can monitor the build here.

Update: The results are in!

All reactions

Sorry, something went wrong.

Uh oh!

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

@typescript-bot

TypeScript Bot (typescript-bot) commented Oct 17, 2022 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the extended test suite on this PR at 3f66f6c. You can monitor the build here.

All reactions

Sorry, something went wrong.

Uh oh!

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

@molisani Michael Molisani (molisani) mentioned this pull request Jan 31, 2023
Type inference for declared enum member assignment #52531
Closed
This was referenced Feb 9, 2023
Specific enum value not comparable with number in 5.0 #52701
Closed
Prefer using enum literal's own base type rather than enum's base type in comparison #52703
Merged
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) mentioned this pull request Feb 28, 2023
Proposal: strictly-typed enums #53013
Open
5 tasks done
@notaphplover notaphplover mentioned this pull request Mar 17, 2023
Enums as union types aren't compatible with strings (5.0) #53304
Closed
@Sweater-Baron

Alex von Brandenfels (Sweater-Baron) commented Mar 17, 2023

Copy link
Copy Markdown

Is this included in a published version of Typescript yet? Based on the comments in this PR thread, it sounds like it should be in Typescript 5.

I'm on Typescript 5.0.2, but getting the error "const enum member initializers can only contain literal values and other computed enum values.", which I believe shouldn't happen if I'm on a version of typescript that includes this code?

I'm copying the example from the PR:

const prefix = '/data';

const enum Routes {
  Parts = `${prefix}/parts`, // "/data/parts"
  Invoices = `${prefix}/invoices`, // "/data/invoices"
}
All reactions

Sorry, something went wrong.

Uh oh!

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

@janbiasi

Jan (janbiasi) commented Mar 20, 2023

Copy link
Copy Markdown

Is this included in a published version of Typescript yet? Based on the comments in this PR thread, it sounds like it should be in Typescript 5.

Alex von Brandenfels (@Sweater-Baron) Yes it is, your example is working perfectly fine running version 5.0.2 (see playground). If you use VSCode make sure that you use your local TypeScript version and not VSCode's version.

tka85 reacted with thumbs down emoji
All reactions
  • 👎 1 reaction

Sorry, something went wrong.

Uh oh!

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

@JordanDC2

Jordan Christiansen (JordanDC2) commented Mar 21, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Is there any plan to implement enum extension like in this playground (or some other way to extend enums)?:

Screen Shot 2023-03-21 at 9 01 53 AM

All reactions

Sorry, something went wrong.

Uh oh!

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

@isaackhoo

isaackhoo commented Mar 21, 2023

Copy link
Copy Markdown

Is this included in a published version of Typescript yet? Based on the comments in this PR thread, it sounds like it should be in Typescript 5.

Alex von Brandenfels (@Sweater-Baron) Yes it is, your example is working perfectly fine running version 5.0.2 (see playground). If you use VSCode make sure that you use your local TypeScript version and not VSCode's version.

I have set my vscode to use 5.0.2, but im still getting the error
image

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

@WORMSS

Colin Richardson (WORMSS) commented Mar 21, 2023

Copy link
Copy Markdown

Jordan Christiansen (@JordanDC2) Not 100% exactly what you asked for..
But I find they work better than enums

https://www.typescriptlang.org/play?#code/MYewdgzgLgBADgJwKYDMCWAPGBeGByAegBMBDKEvAbgFgAoUSWAJRAFcokIcYBvOmATAAKJBFAgAuGAAMAJD0SpMAXwJxR46QBp+ggJJgAbiDTBOUuQuToMqtEZNmI2uspgkuDaDVp0vzNg4IAFEMDjAiJCJuPlpBGAA6JJZ2Th04wQB5BEiESRl5RRtVEBykPJdaNw8Yfx86KABPOCQYFKDQ8MiiADUSABtWTm4mlpAUNsDOTqQIqIBtAGskRvGYUaQ19umw2e6AXXraFFYwYCg0cBgAcxAoEAAKBCmpbZDdud6BoYgASl5lHQ6Ld7g83jNPgkDMZTJxfj4QY83lCHLC-pQgA

Seriosus reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

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

@JordanDC2

Jordan Christiansen (JordanDC2) commented Mar 22, 2023

Copy link
Copy Markdown

Colin Richardson (@WORMSS) yeah thats kind of what im having to work with currently, i just wish it was a capability of Enums since we can have computed values now but not computed keys

All reactions

Sorry, something went wrong.

Uh oh!

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

@Seriosus

Alekz (Seriosus) commented Mar 27, 2023

Copy link
Copy Markdown

Jordan Christiansen (@JordanDC2) Not 100% exactly what you asked for.. But I find they work better than enums

https://www.typescriptlang.org/play?#code/MYewdgzgLgBADgJwKYDMCWAPGBeGByAegBMBDKEvAbgFgAoUSWAJRAFcokIcYBvOmATAAKJBFAgAuGAAMAJD0SpMAXwJxR46QBp+ggJJgAbiDTBOUuQuToMqtEZNmI2uspgkuDaDVp0vzNg4IAFEMDjAiJCJuPlpBGAA6JJZ2Th04wQB5BEiESRl5RRtVEBykPJdaNw8Yfx86KABPOCQYFKDQ8MiiADUSABtWTm4mlpAUNsDOTqQIqIBtAGskRvGYUaQ19umw2e6AXXraFFYwYCg0cBgAcxAoEAAKBCmpbZDdud6BoYgASl5lHQ6Ld7g83jNPgkDMZTJxfj4QY83lCHLC-pQgA

Man, you saved me, thank you.
This is indeed better than using enums or at least when not using literals.

All reactions

Sorry, something went wrong.

Uh oh!

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

@magic-akari magic-akari mentioned this pull request Mar 28, 2023
[TypeScript] const enum should be hoisted swc-project/swc#3648
Closed
@tka85

tka85 commented Apr 1, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Sounds weird, but I'm on Typescript 5.0.2. I'm forcing VSC to use the local installed Typescript version (which it recognizes is 5.0.2 instead of VSC's 4.9.5) and the enum values still get udnerlined with red squiggly line.

export enum TABLES {
    foo = `${config.schema}.foos`,
    bar = `${config.schema}.bars`
}

Any ideas what I'm missing here? I see the playground link posted above by Jan (@janbiasi) and it should be working for 5.0.2. But it's not.

I confirm that the project has 5.0.2 installed with npm ls typescript; only 5.0.2 and no other version exists in the workspace.

maxrbaldwin, vtarelkin, williamrobertson13, Sweater-Baron, and nick4fake reacted with thumbs up emoji
All reactions
  • 👍 5 reactions

Sorry, something went wrong.

Uh oh!

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

@manu0466 Manuel (manu0466) mentioned this pull request Apr 3, 2023
build(deps-dev): bump typescript from 4.9.5 to 5.0.3 desmos-labs/desmjs#419
Closed
@jcalz Joe Calzaretta (jcalz) mentioned this pull request Apr 23, 2023
Make enum indexes non-enumerable #53973
Closed
2 of 5 tasks
@fatcerberus Bruce Pascoe (fatcerberus) mentioned this pull request Apr 25, 2023
Inference regression (5.0.4 vs 4.9.5) with nullable enum function parameter #54005
Closed
@Regiden

Radical Dude (Regiden) commented Apr 28, 2023

Copy link
Copy Markdown

We just tried to update our code base and we noticed a ton of errors. Turns out this change basically means you cannot treat an enum as basically "just" a number anymore? No way to optionally tell TypeScript to allow "optional" values that are basically null?

This is somewhat weird, because you now can't have a fall back state and HAVE to define a "NONE" type.

enum TEST {
    ONE = 1,
    TWO
}

const foo: TEST = 0;

This now is an error. Was there any reason not to allow for a fallback here?

All reactions

Sorry, something went wrong.

Uh oh!

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

@gabriel-calin-lazar

Gabriel-Calin Lazar (gabriel-calin-lazar) commented May 5, 2023

Copy link
Copy Markdown

how come
we have strict enum usages when value is number, when using number literal or enum entry
but
we have strict enum usages when value is string, only when using enum entry - not when using string literal ?

would be really useful to not have this not so obvious difference

you can check some examples here

All reactions

Sorry, something went wrong.

Uh oh!

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

@ahejlsberg

Anders Hejlsberg (ahejlsberg) commented May 5, 2023

Copy link
Copy Markdown
Member Author

Gabriel-Calin Lazar (@gabriel-calin-lazar) See my comment here.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vtarelkin

Valery Tarelkin (vtarelkin) commented May 18, 2023

Copy link
Copy Markdown

tka85 any ideas about it? Also have TS above 5 and it complains

All reactions

Sorry, something went wrong.

Uh oh!

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

@tka85

tka85 commented May 19, 2023

Copy link
Copy Markdown

Valery Tarelkin (@vtarelkin) Nope. No response.

All reactions

Sorry, something went wrong.

Uh oh!

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

@jakebailey

Jake Bailey (jakebailey) commented May 19, 2023

Copy link
Copy Markdown
Member

An old PR is really not the best place to ask for help or report bugs. I would really suggest filing an issue if you want it to be seen by the right people.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vtarelkin

Valery Tarelkin (vtarelkin) commented May 19, 2023

Copy link
Copy Markdown

Jake Bailey (@jakebailey) people are searching over the whole net and hope to find a clue here) maybe you could help us please?)) I have a TS above 5th version and it still complains
image

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

@jakebailey

Jake Bailey (jakebailey) commented May 19, 2023

Copy link
Copy Markdown
Member

Please, please, please, file an issue and fill out the template.

yume-chan, ruialves92, and RyanCavanaugh reacted with thumbs up emoji
All reactions
  • 👍 3 reactions

Sorry, something went wrong.

Uh oh!

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

@jakebailey Jake Bailey (jakebailey) mentioned this pull request Jul 11, 2023
Bad error message for enum initializers #24210
Closed
@timostamm Timo Stamm (timostamm) mentioned this pull request Jul 12, 2023
Add the open/closed behavior for enums to documentation bufbuild/protobuf-es#522
Closed
@nick4fake

Bohdan Yurov (nick4fake) commented Jul 26, 2023 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Jake Bailey (@jakebailey) this issues comes the first google search result. I have typescript 5.1.3 and just noticed the same problem, still trying to find any relevant tickets in this repo.

If there is a solution - it might be helpful to add it here, or at least have a link somewhere in comments

All reactions

Sorry, something went wrong.

Uh oh!

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

@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Jul 26, 2023
@RyanCavanaugh

Ryan Cavanaugh (RyanCavanaugh) commented Jul 26, 2023

Copy link
Copy Markdown
Member

Please file a new issue outlining the problem you're having

All reactions

Sorry, something went wrong.

Uh oh!

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@sandersn Nathan Shively-Sanders (sandersn) sandersn approved these changes
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) RyanCavanaugh approved these changes
@andrewbranch Andrew Branch (andrewbranch) Awaiting requested review from andrewbranch
@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Awaiting requested review from DanielRosenwasser
@weswigham Wesley Wigham (weswigham) Awaiting requested review from weswigham

Uh oh!

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

Assignees

@ahejlsberg Anders Hejlsberg (ahejlsberg)

Labels

Author: Team Breaking Change Would introduce errors in existing code For Milestone Bug PRs that fix a bug with a specific milestone

Projects

PR Backlog
Archived in project

Milestone

TypeScript 5.0.0

Development

Successfully merging this pull request may close these issues.

String enums from string constants Enable constants as computed values for string enums TS 2535 when using const enum values derived from other const enum values Enums does not support literal typing with computed values

Uh oh!

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

20 participants

@ahejlsberg @RyanCavanaugh @typescript-bot @Jack-Works @jakebailey @WORMSS @andreymaslovru @nicojs @hackwaly @Harpush @Sweater-Baron @janbiasi @JordanDC2 @isaackhoo @Seriosus @tka85 @Regiden @gabriel-calin-lazar @vtarelkin @nick4fake
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.