privatenumber / ts-runtime-comparison

Comparison of Node.js TypeScript runtimes
485 stars 8 forks source link

Cannot access ambient const enums when run by `tsx` but no problem by `ts-node` #16

Closed WankkoRee closed 1 year ago

WankkoRee commented 1 year ago

Problem

I declare enum in typings like it:

// src/typings/main/index.d.ts

declare const enum Test {
  hello = 'world',
}

and tsconfig.json like it:

{
  "compilerOptions": {
    "typeRoots": ["src/typings"]
  }
}

and then I try to use enums like it:

// src/main.ts

console.log(Test.hello);

then it will be ReferenceError: Test is not defined.

Expected behavior

print world just like if I run it by ts-node.

I run it by ts-node without problem, so I think may it is a bug for tsx ?

ts-node behavior: https://codesandbox.io/p/sandbox/tsx-bug-in-ts-node-r9h985

tsx behavior: https://codesandbox.io/p/sandbox/tsx-bug-rl55dz

because StackBlitz does not support ts-node, I use CodeSandbox.

Minimal reproduction URL

https://codesandbox.io/p/sandbox/tsx-bug-rl55dz

Version

v3.12.6

Node.js version

v16.17.0

Package manager

yarn

Operating system

Windows

Contributions

privatenumber commented 1 year ago

This doesn't seem relevant here. Did you mean to file this in tsx?

WankkoRee commented 1 year ago

sorry, is my mistake, i dont know why I filed this here.