Title: 7.1 regression: type argument inferred from a union of callback types (`R` | `Promise
Open Graph Title: 7.1 regression: type argument inferred from a union of callback types (`R` | `Promise
X Title: 7.1 regression: type argument inferred from a union of callback types (`R` | `Promise
Description: TypeScript Version The tested TypeScript version is 7.1.0-beta. It also happens in 7.1.0-dev.20261118.1. 7.0.2 infers the expected type. Among the nightlies, 7.1.0-dev.20260721.1 is the last that infers it and 7.1.0-dev.20260722.1 is the...
Open Graph Description: TypeScript Version The tested TypeScript version is 7.1.0-beta. It also happens in 7.1.0-dev.20261118.1. 7.0.2 infers the expected type. Among the nightlies, 7.1.0-dev.20260721.1 is the last that i...
X Description: TypeScript Version The tested TypeScript version is 7.1.0-beta. It also happens in 7.1.0-dev.20261118.1. 7.0.2 infers the expected type. Among the nightlies, 7.1.0-dev.20260721.1 is the last that i...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/65574
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"7.1 regression: type argument inferred from a union of callback types (`R` | `Promise\u003cR | void>`) falls back to its constraint","articleBody":"## TypeScript Version\n\nThe tested TypeScript version is 7.1.0-beta. It also happens in 7.1.0-dev.20261118.1. 7.0.2 infers the expected type. Among the nightlies, 7.1.0-dev.20260721.1 is the last that infers it and 7.1.0-dev.20260722.1 is the first that does not.\n\n## User Goal\n\nThe user tried 7.1.0-beta in their monorepo and saw the emitted declarations of their Hono routes lose their response types. They asked me to narrow it down to a possible TypeScript bug and report it.\n\n## Setup and Action\n\n```ts\ntype TypedResponse\u003cT = unknown, U extends number = number> = { _data: T; _status: U };\ntype HandlerResponse = TypedResponse\u003cany, any> | Promise\u003cTypedResponse\u003cany, any>> | Promise\u003cvoid>;\n\ntype Handler\u003cR extends HandlerResponse> = (next: () => Promise\u003cvoid>) => R;\ntype MiddlewareHandler\u003cR extends HandlerResponse> = (next: () => Promise\u003cvoid>) => Promise\u003cR | void>;\n\ndeclare function route\u003cR extends HandlerResponse = any>(handler: Handler\u003cR> | MiddlewareHandler\u003cR>): R;\ndeclare function json\u003cT, U extends number>(body: T, status: U): TypedResponse\u003cT, U>;\n\nasync function handle(next: () => Promise\u003cvoid>, flag: number) {\n if (flag === 0) return next();\n if (flag === 1) return json({ error: \"missing\" }, 404);\n return json({ role: \"admin\" as const }, 200);\n}\n\nexport const inferred = route((next) => handle(next, 0));\n```\n\n`tsconfig.json`: `{ \"compilerOptions\": { \"strict\": true, \"declaration\": true, \"emitDeclarationOnly\": true } }`\n\nRun `tsc` and read the type of `inferred` in the emitted `.d.ts`.\n\n## Expected and Actual Behavior\n\n**What actually happened**: `inferred` is `HandlerResponse`, the constraint of `R`.\n\n**What I expected**: The type 7.0.2 infers:\n\n```ts\nTypedResponse\u003c{ error: string; }, 404> | TypedResponse\u003c{ role: \"admin\"; }, 200>\n```\n\nThe handler returns `Promise\u003cvoid | TypedResponse\u003c…, 404> | TypedResponse\u003c…, 200>>`, which matches `MiddlewareHandler\u003cR>`'s `Promise\u003cR | void>`. Hono's handler types use this pattern, so typed RPC clients built on it get `{}` response types.\n\nWithout the `next()` branch, 7.1.0-beta infers `Promise\u003cTypedResponse\u003c…, 404> | TypedResponse\u003c…, 200>>`, where 7.0.2 infers `TypedResponse\u003c…, 404> | TypedResponse\u003c…, 200>`.\n\n## Agent Info\n\nClaude Code + Claude Opus 5.5 + Skill Version 1.0\n","author":{"url":"https://github.com/kazu-42","@type":"Person","name":"kazu-42"},"datePublished":"2026-11-19T02:39:50Z","url":"https://github.com/microsoft/TypeScript/issues/65574"}
| 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:1eb2c7ed-9e66-e3e5-5e3f-83c839290346 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 89CC:16EED3:6786B6:8586C4:6B00E12D |
| html-safe-nonce | c3e1a3c4a1af35099c113b24ede92c9046989db1195aa09b2a3a1079cee454b3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OUNDOjE2RUVEMzo2Nzg2QjY6ODU4NkM0OjZCMDBFMTJEIiwidmlzaXRvcl9pZCI6IjYwMjYyNTg1Mzg4MTk1NDMzNDEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 949fc004bc01c6c1c46a0cc6e682eaeb1bb39be77ea9a5c7c5445dc388bd8b8c |
| hovercard-subject-tag | issue:6481145194 |
| 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/65574/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0259e71b61f32bf153b36b7086f9ab1adbdf610201df966a369829c04df7397c/microsoft/TypeScript/issues/65574 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0259e71b61f32bf153b36b7086f9ab1adbdf610201df966a369829c04df7397c/microsoft/TypeScript/issues/65574 |
| og:image:alt | TypeScript Version The tested TypeScript version is 7.1.0-beta. It also happens in 7.1.0-dev.20261118.1. 7.0.2 infers the expected type. Among the nightlies, 7.1.0-dev.20260721.1 is the last that i... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kazu-42 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| 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 | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width