privatenumber / tsx

⚡️ TypeScript Execute | The easiest way to run TypeScript in Node.js
https://tsx.is
MIT License
8.64k stars 132 forks source link

Property not assigned to child class when set by parent #503

Closed adi518 closed 3 months ago

adi518 commented 3 months ago

Acknowledgements

Minimal reproduction URL

https://stackblitz.com/edit/node-5p2jxx?file=index.ts

Version

v0.0.0

Node.js version

v18.18.0

Package manager

npm

Operating system

macOS

Problem & expected behavior (under 200 words)

Contributions

privatenumber commented 3 months ago

Can you make your reproduction minimal?

1 or 2 files if possible.

And remove the types, convert it to JS, and verify it works expectedly in Node.

adi518 commented 3 months ago

Done. You now have three commands: start for JS, start-tsx, and start-ts-node, so you can compare them. Btw, I also observed this behavior with SWC, which makes me suspect it's a strict mode thing or a configuration issue.

privatenumber commented 3 months ago

This is happening because of useDefineForClassFields.

TypeScript (and ts-node) sets the target to ES3 by default, which yields this behavior. But tsx sets the target based on your Node.js runtime version.

Read more about it here: https://esbuild.github.io/content-types/#no-type-system