microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.05k stars 12.49k forks source link

Detect Typescript in Javascript editors opened and inform developer, that he is writing different syntax and it will silently fail (probably) #60428

Open spenat28 opened 1 week ago

spenat28 commented 1 week ago

It would be super helpful to have something like:

Warning: TypeScript syntax detected in .jsx file. 
Would you like to:
[ ] Rename to .tsx
[ ] Remove TypeScript syntax
[ ] Ignore warning

This kind of UX improvement could save developers (especially those transitioning between JS and TS projects) a lot of time and frustration. It seems like a relatively straightforward detection that could help a lot of people!

VSCode already does similar helpful suggestions for other cases (like offering to create files that don't exist when you import them), so this would fit right in with that philosophy.

What it would solve?

It's the classic .jsx vs .tsx gotcha! 😄

This is such a common issue that even experienced developers run into it regularly. The file extension makes all the difference because:

So TypeScript typing just "silently fails" to work in .jsx files without any obvious error message about why the types aren't working.

It's one of those "spend an hour debugging only to realize it's a file extension" moments that every developer has experienced!

(Similar functionality could be created for CSS -> SCSS, ... .)

xiBread commented 1 week ago

There's already an error when using TS syntax in js(x) files. Not sure if this is what you're looking for?

Image