Title: JS value being parsed as a TS type argument · Issue #36662 · microsoft/TypeScript · GitHub
Open Graph Title: JS value being parsed as a TS type argument · Issue #36662 · microsoft/TypeScript
X Title: JS value being parsed as a TS type argument · Issue #36662 · microsoft/TypeScript
Description: TypeScript Version: 3.8.0-dev.20200205 Search Terms: emscripten "type arguments" Code The following code (I added the declaration) was found in the distribution package for viz.js: https://github.com/mdaines/viz.js/releases/download/v2.1...
Open Graph Description: TypeScript Version: 3.8.0-dev.20200205 Search Terms: emscripten "type arguments" Code The following code (I added the declaration) was found in the distribution package for viz.js: https://github.c...
X Description: TypeScript Version: 3.8.0-dev.20200205 Search Terms: emscripten "type arguments" Code The following code (I added the declaration) was found in the distribution package for viz.js: https:...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/36662
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"JS value being parsed as a TS type argument","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\n\r\n\u003c!--\r\nPlease try to reproduce the issue with the latest published version. It may have already been fixed.\r\nFor npm: `typescript@next`\r\nThis is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly\r\n-->\r\n**TypeScript Version:** 3.8.0-dev.20200205\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** emscripten \"type arguments\"\r\n\r\n**Code**\r\n\r\nThe [following code][1] (I added the declaration) was found in the distribution package for viz.js: https://github.com/mdaines/viz.js/releases/download/v2.1.2/lite.render.js. This file is generated by emscripten, so the syntax is a little weird.\r\n\r\n```ts\r\ndeclare let [k, e, a, c, n]: number[];\r\nif ((k | 0) \u003c (e | 0) | (k | 0) > (a \u003c\u003c 16 >> 16 | 0)) {\r\n c[n >> 2] = 1364;\r\n}\r\n```\r\n\r\n[1]: https://www.typescriptlang.org/play/?ts=3.8.0-dev.20200205&ssl=1&ssc=1&pln=4&pc=2#code/CYUwxgNghgTiAEEQBd4G0DWAaeIdRzBwDsBdALnmIFcBbAIxBjVIG4AoASwDN4AKPhngAfeAAYAlPAA8-BKMkj+QhVIB8-KDNkBGAGzw1G-UslSA3u3jWbt22DTFDGgEyl4AXng6AzHoAsHAC+QA\r\n\r\n**Expected behavior:**\r\n\r\nThis is valid JavaScript and should have the same parse as JS.\r\n\r\n**Actual behavior:**\r\n\r\nIf this is parsed as TS, the part between the `\u003c` and the `>` get pulled out as a type annotation, leaving\r\n\r\n```\r\nif ((k | 0)(a \u003c\u003c 16 >> 16 | 0))\r\n```\r\n\r\nwhich is clearly incorrect, as it's trying to call a number. If this is parsed as a JS file (with --allowJs), it produces an error:\r\n\r\n```\r\n$ tsc --allowJs a.js\r\na.js:2:14 - error TS8011: 'type arguments' can only be used in a .ts file.\r\n\r\n2 if ((k | 0) \u003c (e | 0) | (k | 0) > (a \u003c\u003c 16 >> 16 | 0)) {\r\n ~~~~~~~~~~~~~~~~~~\r\n```\r\n\r\nEven if one makes the argument that this is not valid TS syntax, it should still parse the explicitly-JS input.\r\n\r\n**Playground Link:** \u003c!-- A link to a TypeScript Playground \"Share\" link which demonstrates this behavior -->\r\n\r\nhttps://www.typescriptlang.org/play/?ts=3.8.0-dev.20200205&ssl=1&ssc=1&pln=4&pc=2#code/CYUwxgNghgTiAEEQBd4G0DWAaeIdRzBwDsBdALnmIFcBbAIxBjVIG4AoASwDN4AKPhngAfeAAYAlPAA8-BKMkj+QhVIB8-KDNkBGAGzw1G-UslSA3u3jWbt22DTFDGgEyl4AXng6AzHoAsHAC+QA\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? -->\r\n\r\nI was unable to find anything.","author":{"url":"https://github.com/shicks","@type":"Person","name":"shicks"},"datePublished":"2020-02-06T23:04:32Z","url":"https://github.com/microsoft/TypeScript/issues/36662"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4773ea42-5986-8127-9f31-33e6d1167528 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8D0E:A99C2:739813:96F320:6B00D45D |
| html-safe-nonce | 2171be2b6339fe126c4b6001e39bda574d9063b3e58f3cc3aebb4743ed2d8a29 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RDBFOkE5OUMyOjczOTgxMzo5NkYzMjA6NkIwMEQ0NUQiLCJ2aXNpdG9yX2lkIjoiODc4OTc2NTI5MTYzNTY5MjYzNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | a4829029f768f8578a8d9c270601b403af09898ad7ccbb11669de6762a2f231d |
| hovercard-subject-tag | issue:561322243 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/36662/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ed52e8c50e09cbc91c05f12f633b92dfc1feaceb2ceaf8297bf7057b066c8fce/microsoft/TypeScript/issues/36662 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ed52e8c50e09cbc91c05f12f633b92dfc1feaceb2ceaf8297bf7057b066c8fce/microsoft/TypeScript/issues/36662 |
| og:image:alt | TypeScript Version: 3.8.0-dev.20200205 Search Terms: emscripten "type arguments" Code The following code (I added the declaration) was found in the distribution package for viz.js: https://github.c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | shicks |
| hostname | github.com |
| expected-hostname | github.com |
| None | 85bbdfe2b6ba16e234513bc6ceff5d848ef8449820c900692a2b4e67061931e5 |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4943239a6d2c591325dad6e5c313e1cafda877f6 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width