Title: Type-asserting function call on variable initialized using `this` causes false implicit-any in VSCode · Issue #51661 · microsoft/TypeScript · GitHub
Open Graph Title: Type-asserting function call on variable initialized using `this` causes false implicit-any in VSCode · Issue #51661 · microsoft/TypeScript
X Title: Type-asserting function call on variable initialized using `this` causes false implicit-any in VSCode · Issue #51661 · microsoft/TypeScript
Description: TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - Type-asserting function call on variable initialized using `this` causes false implicit-any in VSCode · Issue #51661 · microsoft/TypeScript
Open Graph Description: TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - Type-asserting function call on variable initialized using `this` causes false implicit-any in VSCode · Issue #516...
X Description: TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - Type-asserting function call on variable initialized using `this` causes false implicit-any in VSCode · Issue #516...
Opengraph URL: https://github.com/microsoft/TypeScript
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type-asserting function call on variable initialized using `this` causes false implicit-any in VSCode","articleBody":"# Bug Report\r\n\r\n### 🔎 Search Terms\r\n\r\nasserts, this, vscode, language server, implicit any\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This changed between versions 4.6 and 4.7\r\n- This is also a problem on Nightly (`5.0.0-dev.20221128`)\r\n\r\nThis issue seems to be specific to VSCode's TS support - I have not been able to reproduce it in either the Playground nor the Bug Workbench. `tsc` itself accepts this code with no issues.\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n```ts\r\nconst assertExists: \u003cT extends number>(actual: T | null | undefined) => asserts actual is T = () => {};\r\n\r\ntype Value = { n: number | undefined };\r\nconst callThisFunc = (f: (this: Value) => void): void => {\r\n f.call({ n: 42 });\r\n};\r\n\r\ncallThisFunc(function() {\r\n const maybeN = this.n;\r\n assertExists(maybeN);\r\n});\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nSometimes, usually when freshly loading this code, this works normally. If you edit the function body passed to `callThisFunc` in any way, even stuff like adding superfluous semicolons, `maybeN` will become red-underlined and complain about implicit-`any` on hover. Further appearances of `maybeN` in the function are also treated as `any`.\r\n\r\nThis error does not happen if you do not call `assertExists`, nor does it happen if you give `this` an explicit type, like so:\r\n```ts\r\ncallThisFunc(function(this: Value) {\r\n const maybeN = this.n;\r\n assertExists(maybeN);\r\n});\r\n```\r\n\r\n### 🙂 Expected behavior\r\n\r\nThis should not display any errors in VSCode, and the `assertExists` call should correctly narrow the type to `number`.\r\n","author":{"url":"https://github.com/OxleyS","@type":"Person","name":"OxleyS"},"datePublished":"2022-11-28T10:29:56Z","url":"https://github.com/microsoft/TypeScript/issues/51661"}
| 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 | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:ae234c80-4de0-ea39-59a7-0e4c1b640e2d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E9B0:2C4BED:22AC62C:2C0861F:6B017D4B |
| html-safe-nonce | aeb5564a154ab7f4c0649c7ced3aaf558ac35bdecfa3509b8666ab8a43036c21 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOUIwOjJDNEJFRDoyMkFDNjJDOjJDMDg2MUY6NkIwMTdENEIiLCJ2aXNpdG9yX2lkIjoiMTY3Njg0NTcxMTkzNDcxNzI1OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3f2d087c64f60e5f691b6e94b8667331ebf63b1b4a50070820f8f159d4c97576 |
| hovercard-subject-tag | repository:20929025 |
| 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/microsoft/TypeScript/issues/51661 |
| twitter:image | https://opengraph.githubassets.com/47cde802d3847ff7ce61448bd4f8c3272d012c9a3f2b9085b71a67530bf7bbd6/microsoft/TypeScript |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/47cde802d3847ff7ce61448bd4f8c3272d012c9a3f2b9085b71a67530bf7bbd6/microsoft/TypeScript |
| og:image:alt | TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - Type-asserting function call on variable initialized using `this` causes false implicit-any in VSCode · Issue #516... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-cache |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width