Title: `null` gets accidentally eliminated when narrowing by undefined's equality · Issue #57693 · microsoft/TypeScript · GitHub
Open Graph Title: `null` gets accidentally eliminated when narrowing by undefined's equality · Issue #57693 · microsoft/TypeScript
X Title: `null` gets accidentally eliminated when narrowing by undefined's equality · Issue #57693 · microsoft/TypeScript
Description: 🔎 Search Terms null undefined narrow narrowing reduction equality narrowby 🕗 Version & Regression Information This is the behavior in every version I tried* *it worked differently in 5.1-5.3 because those had a bug in them ( #57202 ) ⏯ P...
Open Graph Description: 🔎 Search Terms null undefined narrow narrowing reduction equality narrowby 🕗 Version & Regression Information This is the behavior in every version I tried* *it worked differently in 5.1-5.3 becaus...
X Description: 🔎 Search Terms null undefined narrow narrowing reduction equality narrowby 🕗 Version & Regression Information This is the behavior in every version I tried* *it worked differently in 5.1-5.3 be...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/57693
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`null` gets accidentally eliminated when narrowing by undefined's equality","articleBody":"### 🔎 Search Terms\r\n\r\nnull undefined narrow narrowing reduction equality narrowby\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This is the behavior in every version I tried* \r\n\r\n*it worked differently in 5.1-5.3 because those had a bug in them ( https://github.com/microsoft/TypeScript/pull/57202 )\r\n\r\n### ⏯ Playground Link\r\n\r\nhttps://www.typescriptlang.org/play?ts=5.5.0-dev.20240308#code/C4TwDgpgBAggdiA8gIwFYQMbCgXigJUwHsAnAEwB4BnYEgSzgHMAaKAQwQD4BuAKFEhQAysDbBoeeEjSZgfXmUwAbNiWgAzAK5wsdInCgALNlUQB3OAAUSRSCVAUAKlAgAPcXDJVYCFOiycABS8UFBEMlgAXFCOzCFQYDZg0da2EPYgANIQIHEAlNGJtlB03gDWOUTqMfIM4iTqbBjQIqQQFEK4wqLinFAA3vFUEMAiYu2ZLu4QnuWV1UJBFSDRmawAbmxKmhDRQgDamQC6BVDrRHRkfAC+vLxuYKTYWjrAegZUIDqtaqlgFPFOm4PF5uuM4qFLFMQd5LKo3lsOpwIVBJsCZqDllVhHEgjQ2ntgG0kawimAqClWMtVnkBvEMPoaGctjsusZTBY-ulQIEyVQqTlaQB+BJJKj7ZZHKDRbSKdQMCBXO6hOjVQKbbYSHB4WUQeVwRW0tTATQkOB8UIAektUGAhlKLhINhIVCGRLUADphqMehBAssNiyIHl5FabXaHVRDERNEoyHAAOTYNjqdSyW2GaACaAcEDRsysMwQBPrHNKNRsMggKAYTMYCpkdiMNgMJl26BUNgAWyz9qY8VVUHVQdw2qguv1hqgxtN5vi1qgVE0ZEUcGASmrdGwS4wzUVrtC+M93rG4n9OUDmpDvFuQA\r\n\r\n### 💻 Code\r\n\r\n```ts\r\ntype AnyObject = Record\u003cstring, any>;\r\ntype State = AnyObject;\r\n\r\ndeclare function hasOwnProperty\u003cT extends AnyObject>(\r\n object: T,\r\n prop: PropertyKey,\r\n): prop is keyof T;\r\n\r\ninterface Store\u003cS = State> {\r\n setState\u003cK extends keyof S>(key: K, value: S[K]): void;\r\n}\r\n\r\nexport function syncStoreProp\u003c\r\n S extends State,\r\n P extends Partial\u003cS>,\r\n K extends keyof S,\r\n>(store: Store\u003cS>, props: P, key: K) {\r\n const value = hasOwnProperty(props, key) ? props[key] : undefined;\r\n\r\n if (value === undefined) return;\r\n // this errors\r\n store.setState(key, value);\r\n\r\n // this shouldn't affect the type anyhow, we've already checked against the same thing\r\n if (value === undefined) return;\r\n // suddently it succeeds\r\n store.setState(key, value);\r\n}\r\n```\r\n\r\n\r\n### 🙁 Actual behavior\r\n\r\none of the calls errorrs while the other one doesn't\r\n\r\n### 🙂 Expected behavior\r\n\r\ni'd expect consistent behavior at both call sites\r\n\r\n### Additional information about the issue\r\n\r\noriginally reported by @diegohaz here: https://twitter.com/diegohaz/status/1765674095293747628","author":{"url":"https://github.com/Andarist","@type":"Person","name":"Andarist"},"datePublished":"2024-03-08T09:02:45Z","url":"https://github.com/microsoft/TypeScript/issues/57693"}
| 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:c7b6d03d-1cce-522a-b0f1-7ac36cf85f43 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9A8A:34DB8F:1D6AB04:274838B:6B01747D |
| html-safe-nonce | 3bc81744f39eb353f990a8690ed17eac61918b42ca20a385eba380dca480dcfd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QThBOjM0REI4RjoxRDZBQjA0OjI3NDgzOEI6NkIwMTc0N0QiLCJ2aXNpdG9yX2lkIjoiMTcyNjYxODc5OTQzNzg3MDIwNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5455cf96a3f512398bc62250cb2f65a41177df60f4161756b6b5da4939bdc93a |
| hovercard-subject-tag | issue:2175591047 |
| 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/57693/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2c6e8844ace60b2117afddb462997b1d1e6ee3c918105ed77ee9995749811994/microsoft/TypeScript/issues/57693 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2c6e8844ace60b2117afddb462997b1d1e6ee3c918105ed77ee9995749811994/microsoft/TypeScript/issues/57693 |
| og:image:alt | 🔎 Search Terms null undefined narrow narrowing reduction equality narrowby 🕗 Version & Regression Information This is the behavior in every version I tried* *it worked differently in 5.1-5.3 becaus... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Andarist |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width