-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Generic type arguments are sometimes also valid JavaScript comparison expressions #33639
Comments
Nice construction! |
We can create a more interesting construction, let as=()=>0,m=[].map<0>as(()=>[]);console.log(`I'm ${!m?'Java':'Type'}Script`) This piece of code won't emit any error on a default-configured I've also tried some popular TS runtime. The result is:
|
Nice! There's a shorter construction due to @mikesamuel viz. Semantic supersetting is hard - I think it's a dead horse not worth beating further. |
TypeScript Version: 3.4.0-dev.201xxxxx
Search Terms:
superset, syntactic, semantic, heuristic, parsing
Code
Expected behavior:
When run as JS (since it's valid JS) it should output the same as when run as TS.
Actual behavior:
The behavior is different in JavaScript and TypeScript
Playground Link:
https://www.typescriptlang.org/play/#code/GYVwdgxgLglg9mABMAFAD0QXkQbwL4CUuAsAFCKIAmcEIAtgKZhQB0ARnJQJ4sxhgMATgBUGaKFjIUKAAwCSAcjqIAJDinSKAQ0EBzekygBnANoBGALpZM2YFoA2RhogD8GzQCIAVloBuWj0QALndpDyguAAcGDw08IwhBGEioGQBuMjwyewYJAAssRBQiTAA+RA8PDNJUPJYtSMj7LgAeAGUoJLBdABpEAHk2LwZoUpRwqJiCAmqgA
Related Issues:
#26179
Note
I wrote about this at some length https://medium.com/@jasvir/monoglots-when-a-subset-is-not-1604e3a51d9 because I thought it was just cute but not serious. I was inspired to file it here by a comment @erights made in a bug filed against TC39 (tc39/ecma262#1681) on JS failing to be a superset of JSON that resulted in a security bug.
The text was updated successfully, but these errors were encountered: