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

Problem with native TypeScript when use enum type #4536

Open
2 tasks done
ChacaraKairo opened this issue Jan 19, 2025 · 3 comments
Open
2 tasks done

Problem with native TypeScript when use enum type #4536

ChacaraKairo opened this issue Jan 19, 2025 · 3 comments

Comments

@ChacaraKairo
Copy link

ChacaraKairo commented Jan 19, 2025

Node.js Version

v23.6.0

NPM Version

10.9.2

Subsystem

TypeScript

Description

In this version we can use TypeScript native, but when I was using a enum type for my variable happend a problem with the native case

Minimal Reproduction

// enum

enum Cores {
  'VERMELHO',
  'AZUL',
  'AMARELO',
  'BRANCO',
  'PRETO',
}
console.log(Cores);

enum Cores1 {
  vermelho = 'VERMELHO',
  azul = 'AZUL',
  amarelo = 'AMARELO',
  branco = 'BRANCO',
  preto = 'PRETO',
}
console.log(Cores1);

enum Numbers {
  zero = 0,
  um = 1,
  dois = 2,
  tres = 3,
  quatro = 4,
  cinco = 5,
  seis = 6,
  sete = 7,
  oito = 8,
  nove = 9,
  dez = 10,
}

// console.log(Cores);

Output

node 'enumType.ts'
node:internal/modules/typescript:52
    throw new ERR_INVALID_TYPESCRIPT_SYNTAX(error);
    ^

SyntaxError [ERR_INVALID_TYPESCRIPT_SYNTAX]:   x TypeScript enum is not supported in strip-only mode
    ,-[3:1]
  1 |     // enum
  2 |
  3 | ,-> enum Cores {
  4 | |     'VERMELHO',
  5 | |     'AZUL',
  6 | |     'AMARELO',
  7 | |     'BRANCO',
  8 | |     'PRETO',
  9 | `-> }
 10 |     console.log(Cores);
 11 |
 11 |     enum Cores1 {
    `----
  x TypeScript enum is not supported in strip-only mode
    ,-[12:1]
  9 |     }
 10 |     console.log(Cores);
 11 |
 12 | ,-> enum Cores1 {
 13 | |     vermelho = 'VERMELHO',
 14 | |     azul = 'AZUL',
 15 | |     amarelo = 'AMARELO',
 16 | |     branco = 'BRANCO',
 17 | |     preto = 'PRETO',
 18 | `-> }
 19 |     console.log(Cores1);
 20 |
 20 |     enum Numbers {
    `----
  x TypeScript enum is not supported in strip-only mode
    ,-[21:1]
 18 |     }
 19 |     console.log(Cores1);
 20 |
 21 | ,-> enum Numbers {
 22 | |     zero = 0,
 23 | |     um = 1,
 24 | |     dois = 2,
 25 | |     tres = 3,
 26 | |     quatro = 4,
 27 | |     cinco = 5,
 28 | |     seis = 6,
 29 | |     sete = 7,
 30 | |     oito = 8,
 31 | |     nove = 9,
 32 | |     dez = 10,
 33 | `-> }
 34 |
 35 |     // console.log(Cores);
    `----

    at parseTypeScript (node:internal/modules/typescript:52:11)
    at processTypeScriptCode (node:internal/modules/typescript:98:42)
    at stripTypeScriptModuleTypes (node:internal/modules/typescript:132:10)
    at Module._compile (node:internal/modules/cjs/loader:1691:15)
    at Object.loadTS [as .ts] (node:internal/modules/cjs/loader:1831:10)
    at Module.load (node:internal/modules/cjs/loader:1473:32)
    at Function._load (node:internal/modules/cjs/loader:1285:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:234:24)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:151:5) {
  code: 'ERR_INVALID_TYPESCRIPT_SYNTAX'
}

Before You Submit

  • I have looked for issues that already exist before submitting this
  • My issue follows the guidelines in the README file, and follows the 'How to ask a good question' guide at https://stackoverflow.com/help/how-to-ask
@ljharb
Copy link
Member

ljharb commented Jan 19, 2025

This is intentional, since enums can't be stripped (since they produce a runtime value). You can use --experimental-transform-types, transpile, or stop using enums.

@Feuerhamster
Copy link

Same Issue here.

@ljharb Stop using enums? What?

@ljharb
Copy link
Member

ljharb commented Jan 23, 2025

@Feuerhamster yes, it’s pretty widely known that enums should be avoided; this is one of tons of google results explaining why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants