Title: Incorrect type inference with indexer leads to TS2322 · Issue #28602 · microsoft/TypeScript · GitHub
Open Graph Title: Incorrect type inference with indexer leads to TS2322 · Issue #28602 · microsoft/TypeScript
X Title: Incorrect type inference with indexer leads to TS2322 · Issue #28602 · microsoft/TypeScript
Description: TypeScript Version: 3.1.1 Search Terms: Incorrect type inference, TS2322 class One { } class Two { public prop: One | null = null; } const aTwo = new Two(); aTwo.prop = null; // makes TypeScript infer that the type of aTwo.prop is null b...
Open Graph Description: TypeScript Version: 3.1.1 Search Terms: Incorrect type inference, TS2322 class One { } class Two { public prop: One | null = null; } const aTwo = new Two(); aTwo.prop = null; // makes TypeScript in...
X Description: TypeScript Version: 3.1.1 Search Terms: Incorrect type inference, TS2322 class One { } class Two { public prop: One | null = null; } const aTwo = new Two(); aTwo.prop = null; // makes TypeScript in...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/28602
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect type inference with indexer leads to TS2322","articleBody":"**TypeScript Version:** 3.1.1\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** Incorrect type inference, TS2322\r\n\r\n\tclass One\r\n\t{\r\n\t}\r\n\tclass Two\r\n\t{\r\n\t\tpublic prop: One | null = null;\r\n\t}\r\n\tconst aTwo = new Two();\r\n\taTwo.prop = null;\t// makes TypeScript infer that the type of aTwo.prop is null but only when using indexer syntax which...\r\n\taTwo[\"prop\"] = new One();\t// results in TS2322: Type 'One' is not assignable to type null on this line\r\n\taTwo.prop = new One();\t// this line is however fine\r\n\r\nAlso...\r\n\r\n\taTwo.prop = null; \t// commenting this out or\r\n\t// aTwo.prop = new One();\t// uncommenting this (when it's place before)\r\n\taTwo[\"prop\"] = new One();\t// makes the TS2322 error on this line go away\r\n\r\n\r\n\r\n**Expected behavior:** aTwo[\"prop\"] = new One(); should not result in an error\r\n\r\n**Actual behavior:** It results in TS2322.\r\n\r\n**Playground Link:** \u003c!-- A link to a TypeScript Playground \"Share\" link which demonstrates this behavior -->\r\n\r\n**Related Issues:** The title of this sounds similar to #17011 but this is different and this is new in TypeScript 3.1 (AFAICT) and wasn't an issue in TypeScript 3.0.\r\n","author":{"url":"https://github.com/Manish3177","@type":"Person","name":"Manish3177"},"datePublished":"2018-11-19T15:50:55Z","url":"https://github.com/microsoft/TypeScript/issues/28602"}
| 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:5a926b0d-7da4-2a25-d30c-1b270a9f190a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E198:2D066D:1A2045:23E3E2:6B046659 |
| html-safe-nonce | 726b3dc71aa061385eaa048c44c0f7bb5196b3e55bceb70298622d066537fda6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMTk4OjJEMDY2RDoxQTIwNDU6MjNFM0UyOjZCMDQ2NjU5IiwidmlzaXRvcl9pZCI6IjY1MDUyNTg4MTY2NjAzMzQxNjkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 36435caead5506276fcfe39c5887cbc9f0247ff57e055399cee792307b7cf4b4 |
| hovercard-subject-tag | issue:382276648 |
| 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/28602/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c19fd35153d7442944a01a2c93220231c8cd9bc24b6fc75714ffad09a6ab5d36/microsoft/TypeScript/issues/28602 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c19fd35153d7442944a01a2c93220231c8cd9bc24b6fc75714ffad09a6ab5d36/microsoft/TypeScript/issues/28602 |
| og:image:alt | TypeScript Version: 3.1.1 Search Terms: Incorrect type inference, TS2322 class One { } class Two { public prop: One | null = null; } const aTwo = new Two(); aTwo.prop = null; // makes TypeScript in... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Manish3177 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 83e4c0e58c5162177f3c161c5fbad38527ae04c11ac14980f9f9d85ae2027b1f |
| 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 | ca4d07a7cef4e4b75f821dc25e7300d80c1450a9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width