Title: Aggressive "used before assigned" with strictNullChecks · Issue #9757 · microsoft/TypeScript · GitHub
Open Graph Title: Aggressive "used before assigned" with strictNullChecks · Issue #9757 · microsoft/TypeScript
X Title: Aggressive "used before assigned" with strictNullChecks · Issue #9757 · microsoft/TypeScript
Description: TypeScript Version: 2.0.0 (beta) Code // @strictNullChecks: true function on(event: string, callback: () => void): { destroy(): void; } { return { destroy() { /* nothing */ } }; } const handle = on('example', () => { handle.destroy(); //...
Open Graph Description: TypeScript Version: 2.0.0 (beta) Code // @strictNullChecks: true function on(event: string, callback: () => void): { destroy(): void; } { return { destroy() { /* nothing */ } }; } const handle = on...
X Description: TypeScript Version: 2.0.0 (beta) Code // @strictNullChecks: true function on(event: string, callback: () => void): { destroy(): void; } { return { destroy() { /* nothing */ } }; } const handle =...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/9757
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Aggressive \"used before assigned\" with strictNullChecks","articleBody":"**TypeScript Version:** 2.0.0 (beta)\n\n**Code**\n\n``` ts\n// @strictNullChecks: true\n\nfunction on(event: string, callback: () => void): { destroy(): void; } {\n return {\n destroy() {\n /* nothing */\n }\n };\n}\n\nconst handle = on('example', () => {\n handle.destroy(); // error TS2454: Variable 'handle' is used before being assigned.\n});\n```\n\n**Expected behavior:**\n\nCompile without errors.\n\n**Actual behavior:** \n\nError that `handle` is being used before it is assigned.\n\nIt seems to be overly aggressive behaviour which means using block scoped variables in a callback is causing usability issues. Shouldn't flow control assumed that functions would be resolved after the function returns a value?\n\nSeems to be a little bit related to #9382, but in this case, the type is resolvable (and `handle.destroy()` provides insight. I also noticed that in VSCode, while other compiler errors are displaying, this one isn't getting flagged in the IDE (that may still just be my setup though).\n","author":{"url":"https://github.com/kitsonk","@type":"Person","name":"kitsonk"},"datePublished":"2016-07-15T11:49:20Z","url":"https://github.com/microsoft/TypeScript/issues/9757"}
| 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:16de299e-dae9-2059-cbc0-3fb3d64d02c1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CBF0:D0E46:A91B52:E0D840:6B00EA7F |
| html-safe-nonce | e92136ee8dca0a741b3cb86c32e3bd86216fbb5f67dd203e3dc646e25d896bc9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQkYwOkQwRTQ2OkE5MUI1MjpFMEQ4NDA6NkIwMEVBN0YiLCJ2aXNpdG9yX2lkIjoiNTcyNjUxMzU0ODYyMDc4NjMwMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 10442874ec531b374d7c87e5efa0315342e7ac3edd12c8c8702d175bfcea7e43 |
| hovercard-subject-tag | issue:165770401 |
| 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/9757/issue_layout |
| twitter:image | https://opengraph.githubassets.com/988d7375f55df5a8e064a57e31f3990ea6615f399731e91094b19f82beb588f2/microsoft/TypeScript/issues/9757 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/988d7375f55df5a8e064a57e31f3990ea6615f399731e91094b19f82beb588f2/microsoft/TypeScript/issues/9757 |
| og:image:alt | TypeScript Version: 2.0.0 (beta) Code // @strictNullChecks: true function on(event: string, callback: () => void): { destroy(): void; } { return { destroy() { /* nothing */ } }; } const handle = on... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kitsonk |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width