Title: Unexpected "property is not assignable to type 'undefined'" on dynamic assignment · Issue #61409 · microsoft/TypeScript · GitHub
Open Graph Title: Unexpected "property is not assignable to type 'undefined'" on dynamic assignment · Issue #61409 · microsoft/TypeScript
X Title: Unexpected "property is not assignable to type 'undefined'" on dynamic assignment · Issue #61409 · microsoft/TypeScript
Description: 🔎 Search Terms strictNullChecks "not assignable" "to type 'undefined'" 🕗 Version & Regression Information This changed between versions 3.3.3 and 3.5.1 All newer versions have this behavior ⏯ Playground Link https://www.typescriptlang.or...
Open Graph Description: 🔎 Search Terms strictNullChecks "not assignable" "to type 'undefined'" 🕗 Version & Regression Information This changed between versions 3.3.3 and 3.5.1 All newer versions have this behavior ⏯ Playg...
X Description: 🔎 Search Terms strictNullChecks "not assignable" "to type 'undefined'" 🕗 Version & Regression Information This changed between versions 3.3.3 and 3.5.1 All newer ver...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/61409
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unexpected \"property is not assignable to type 'undefined'\" on dynamic assignment","articleBody":"### 🔎 Search Terms\n\nstrictNullChecks \"not assignable\" \"to type 'undefined'\"\n\n### 🕗 Version & Regression Information\n\n- This changed between versions 3.3.3 and 3.5.1\n All newer versions have this behavior\n\n\n### ⏯ Playground Link\n\nhttps://www.typescriptlang.org/play/?#code/JYOwLgpgTgZghgYwgAgHIHsAmEAKV0AOAzsgN4BQyVycA-AFzIgCuAtgEbQDcl17DyImCigA5jwC+5cgnQghydCNGg4AG0YZseQiQC8ZCT1nywyMHCiiIYTVlz5iyA6SPS1N5AUcBGRgGsIAE90GDR7HScDAHI4aJ4LKxsAbW9CHwBdZ0VlVTVU3wyuZAB6EuQAdyV-IndPNIIAJgDg0PDtR31kWOiaEkCQsK0HXQTLazACwkasgyVgFRB1Kaai0vKAUSh8KGkTBQaiRgBBbbgggB4BtuHIogA+bOSi8hglZAAKfbMGxTDDgCUZF4VESExWsxyCzyEOKZWQWx25CkQA\n\n### 💻 Code\n\n```ts\ninterface NodeProps {\n a?: number;\n b?: string;\n}\n\nconst original: NodeProps = {};\nconst target: NodeProps = {};\n\nlet prop1: keyof NodeProps = 'a';\ntarget[prop1] = original[prop1]; // works\n\nlet prop2: keyof NodeProps = 'a' as keyof NodeProps;\ntarget[prop2] = original[prop2]; // Error\n\nconst props: Array\u003ckeyof NodeProps> = [];\nfor (const prop of props) {\n target[prop] = original[prop]; // Error\n}\n```\n\n\n### 🙁 Actual behavior\n\nGot unexpected errors:\n```\nType 'string | number | undefined' is not assignable to type 'undefined'.\n Type 'string' is not assignable to type 'undefined'.\n```\n\n### 🙂 Expected behavior\n\nShould produce no errors\n\n### Additional information about the issue\n\nSeems to be closely related to https://github.com/microsoft/TypeScript/issues/59969 - disabling `strictNullChecks` option changes the error text, but essentially error stays the same.\n\nError produced with `strictNullChecks`:\n```\nType 'string | number' is not assignable to type 'never'.\n Type 'string' is not assignable to type 'never'.\n```","author":{"url":"https://github.com/DimaIT","@type":"Person","name":"DimaIT"},"datePublished":"2025-03-12T15:02:11Z","url":"https://github.com/microsoft/TypeScript/issues/61409"}
| 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:8a687778-6546-7b13-e9f3-3a3f8d18e1e5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A33A:1DB641:B2D5B9:E7C79F:6B00E79B |
| html-safe-nonce | a08cdd754cd66508532ca65923fbd0d51c4856254cb65139347dd3b0480ba3d9 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzNBOjFEQjY0MTpCMkQ1Qjk6RTdDNzlGOjZCMDBFNzlCIiwidmlzaXRvcl9pZCI6IjY5ODUxMTYwOTA4MDAwNzI2MDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1b26b48d3e41b202cc94065f022d03db9f6cca59639f55088b8f076f3a24f53c |
| hovercard-subject-tag | issue:2914277733 |
| 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/61409/issue_layout |
| twitter:image | https://opengraph.githubassets.com/059c69cd0cc554a555bdda317e1ad758683a1044a2009ffec0b2b6f275e516ac/microsoft/TypeScript/issues/61409 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/059c69cd0cc554a555bdda317e1ad758683a1044a2009ffec0b2b6f275e516ac/microsoft/TypeScript/issues/61409 |
| og:image:alt | 🔎 Search Terms strictNullChecks "not assignable" "to type 'undefined'" 🕗 Version & Regression Information This changed between versions 3.3.3 and 3.5.1 All newer versions have this behavior ⏯ Playg... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | DimaIT |
| hostname | github.com |
| expected-hostname | github.com |
| None | 27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14 |
| 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 | 624179fb8b88d26ba5bba08894eb60a1c5a1d93d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width