Title: Type narrowing not applied for nested types when passing to function · Issue #62525 · microsoft/TypeScript · GitHub
Open Graph Title: Type narrowing not applied for nested types when passing to function · Issue #62525 · microsoft/TypeScript
X Title: Type narrowing not applied for nested types when passing to function · Issue #62525 · microsoft/TypeScript
Description: 🔎 Search Terms discriminant property, ... 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ for entries about type narrowing ⏯ Playground Link https://www.typescriptlang.org/play/?ts...
Open Graph Description: 🔎 Search Terms discriminant property, ... 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ for entries about type narrowing ⏯ Playground Link...
X Description: 🔎 Search Terms discriminant property, ... 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ for entries about type narrowing ⏯ Playground ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/62525
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type narrowing not applied for nested types when passing to function","articleBody":"### 🔎 Search Terms\n\ndiscriminant property, ...\n\n### 🕗 Version & Regression Information\n\n- This is the behavior in every version I tried, and I reviewed the FAQ for entries about type narrowing\n\n\n### ⏯ Playground Link\n\nhttps://www.typescriptlang.org/play/?ts=6.0.0-dev.20251001#code/C4TwDgpgBAogdsAlqKBeAUFKAfKBvTLI0SALigCIB7OCCgbkKKjgEMBbCcgZ2ACdEcAOY4WAVwA2ExswC+hXAWZYSXSsADuVBkyJtOPfoJG44k6bvlZcYuABMIAM0EQ7jdI9sBjJDRYcIACUIAEcxRD5XAAo1PH8DKF4BYShZAEp8eU84H0Q-JONgsIjopPJEo2EMvHkPb184KGAIXhjyeCRQasJERygYqAAyQagIADp9CG7mAuEi8Mi7GImAtPdmSfmSpamZPQCtxYHWbibwCCo+6BG8SfJVS9GVznS9+XkgA\n\n### 💻 Code\n\n```ts\ntype Entity =\n | {\n type: \"one\";\n name: string | null;\n }\n | {\n type: \"two\";\n name: string | null;\n }\n | undefined;\n\nfunction nameRequired(e: { name: string }) {}\nfunction stringRequired(str: string) {}\n\nfunction test(e: Entity) {\n if (e && e.name) {\n stringRequired(e.name);\n\n // Fails\n nameRequired(e);\n\n // Which seemingly has the same types as the above, succeeds.\n nameRequired(e as typeof e & {name: typeof e.name});\n }\n}\n```\n\n\n### 🙁 Actual behavior\n\nReports a type error:\n```\nArgument of type '{ type: \"one\"; name: string | null; } | { type: \"two\"; name: string | null; }' is not assignable to parameter of type '{ name: string; }'.\n Type '{ type: \"one\"; name: string | null; }' is not assignable to type '{ name: string; }'.\n Types of property 'name' are incompatible.\n Type 'string | null' is not assignable to type 'string'.\n Type 'null' is not assignable to type 'string'.\n```\n\n### 🙂 Expected behavior\n\nShould not report a type error.\n\n### Additional information about the issue\n\nIssues I've found that could possibly be related:\n* https://github.com/microsoft/TypeScript/issues/53202\n* https://github.com/microsoft/TypeScript/issues/18758","author":{"url":"https://github.com/SimonSimCity","@type":"Person","name":"SimonSimCity"},"datePublished":"2025-10-02T07:39:18Z","url":"https://github.com/microsoft/TypeScript/issues/62525"}
| 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:6d48bce4-2f38-893f-f958-7966c0b14104 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AEE4:928E2:BCFC73:FDA4B7:6B00F776 |
| html-safe-nonce | efe58606caf83c361e98eb10a4c9f715eaad9d9b65926f9a321a657fdcf66c99 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRUU0OjkyOEUyOkJDRkM3MzpGREE0Qjc6NkIwMEY3NzYiLCJ2aXNpdG9yX2lkIjoiNzY4NTU0NDY5NjA3NjEwNTU5MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f2262abd52b9dc35539eb9eb61cc17790a7fedf161c3bf5ea4e7b50eb291c9c6 |
| hovercard-subject-tag | issue:3476436219 |
| 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/62525/issue_layout |
| twitter:image | https://opengraph.githubassets.com/62944520ba241f29b7045affbb5a1da4efe71fa0edcaa572cafd1ef1b69f7381/microsoft/TypeScript/issues/62525 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/62944520ba241f29b7045affbb5a1da4efe71fa0edcaa572cafd1ef1b69f7381/microsoft/TypeScript/issues/62525 |
| og:image:alt | 🔎 Search Terms discriminant property, ... 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ for entries about type narrowing ⏯ Playground Link... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | SimonSimCity |
| 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 | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width