Title: Null inference of constants within callbacks · Issue #8880 · microsoft/TypeScript · GitHub
Open Graph Title: Null inference of constants within callbacks · Issue #8880 · microsoft/TypeScript
X Title: Null inference of constants within callbacks · Issue #8880 · microsoft/TypeScript
Description: TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - Null inference of constants within callbacks · Issue #8880 · microsoft/TypeScript
Open Graph Description: TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - Null inference of constants within callbacks · Issue #8880 · microsoft/TypeScript
X Description: TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - Null inference of constants within callbacks · Issue #8880 · microsoft/TypeScript
Opengraph URL: https://github.com/microsoft/TypeScript
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Null inference of constants within callbacks","articleBody":"**TypeScript Version:** \n\n1.9.0-dev.20160528-1.0\n\n**Code**\n\n``` ts\nfunction printString() {\n const myString: string|null = 'Hello';\n if (myString == null) {\n return;\n }\n setTimeout(() => {\n console.log('String length was ' + myString.length);\n }, 100);\n}\nprintString();\n```\n\n**Actual behavior:** \n\nWhen compiled with `--strictNullChecks`, this code fails:\n\n```\ntestcase.ts(7,44): error TS2531: Object is possibly 'null'.\n```\n\n**Expected behavior:**\n\nNull inference works fine within the immediate `printString` scope, but it's disabled inside closures.\n\nThis behavior makes sense for variables, since otherwise I could write something like this, that would make `myString` actually become null when it's read and fail:\n\n``` ts\nfunction printString() {\n let myString: string|null = 'Hello';\n if (myString == null) {\n return;\n }\n setTimeout(() => {\n console.log('String length was ' + myString.length);\n }, 100);\n myString = null;\n}\nprintString();\n```\n\nOn the other hand, constants don't allow this, so their non-nullity can be guaranteed if they were checked before the closure was declared.\n","author":{"url":"https://github.com/ntrrgc","@type":"Person","name":"ntrrgc"},"datePublished":"2016-05-28T18:44:05Z","url":"https://github.com/microsoft/TypeScript/issues/8880"}
| 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:d60ccc51-7fc9-9d04-0106-07867026bcb8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B632:19114D:BF8D63:F787A8:6B00EA80 |
| html-safe-nonce | 8106f175b224c5910bf669b27e79d638f7810328281b23f0ec4afb14af5af65c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNjMyOjE5MTE0RDpCRjhENjM6Rjc4N0E4OjZCMDBFQTgwIiwidmlzaXRvcl9pZCI6IjE2OTc4NzQ1NDE4MzA3OTM4NTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | ac78d0aaa70fc5951fed390a34ee3d69b1dda1e907d6559300c0c981ce6675c3 |
| 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/8880 |
| twitter:image | https://opengraph.githubassets.com/1f843281190b2c7429603681aa8d9fd8bf4ea097561976135e9c5d266676c0e0/microsoft/TypeScript |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1f843281190b2c7429603681aa8d9fd8bf4ea097561976135e9c5d266676c0e0/microsoft/TypeScript |
| og:image:alt | TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - Null inference of constants within callbacks · Issue #8880 · microsoft/TypeScript |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| 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 | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width