Title: TypeScript ignoring checks for deeply nested computed object types · Issue #56138 · microsoft/TypeScript · GitHub
Open Graph Title: TypeScript ignoring checks for deeply nested computed object types · Issue #56138 · microsoft/TypeScript
X Title: TypeScript ignoring checks for deeply nested computed object types · Issue #56138 · microsoft/TypeScript
Description: 🔎 Search Terms inference, deeply nested, no error, type evaluation, typebox, hkt 🕗 Version & Regression Information Hi, I've come across some unusual behavior where TypeScript seems to be skipping checks for certain kinds of computed typ...
Open Graph Description: 🔎 Search Terms inference, deeply nested, no error, type evaluation, typebox, hkt 🕗 Version & Regression Information Hi, I've come across some unusual behavior where TypeScript seems to be skipping ...
X Description: 🔎 Search Terms inference, deeply nested, no error, type evaluation, typebox, hkt 🕗 Version & Regression Information Hi, I've come across some unusual behavior where TypeScript seems to be s...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/56138
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TypeScript ignoring checks for deeply nested computed object types","articleBody":"### 🔎 Search Terms\r\n\r\ninference, deeply nested, no error, type evaluation, typebox, hkt\r\n\r\n### 🕗 Version & Regression Information\r\n\r\nHi, \r\n\r\nI've come across some unusual behavior where TypeScript seems to be skipping checks for certain kinds of computed types. This seems to be specific to deeply nested object types that are computed via intersection. I note that the language service is reporting the correct type information in editor, however the compiler seems to be skipping checks on the reported type. This behavior can be observed using the TypeBox library, specifically for object types at least 2 levels deep.\r\n\r\n- This is the behavior in every version I tried (5.1.6 onwards)\r\n\r\n\r\n\r\n\r\n\r\n\r\n### ⏯ Playground Link\r\n\r\n[TypeScript Link Here](https://www.typescriptlang.org/play?#code/PTAEFpK6dv4Yp8BQJQHkBOBLA5jgHYCGANqAMqE4AONApgC5pjJvsefQr0AeNAeyyNQjAJ4NQASUI0AriIC8lRsUY4AxgB5xDAQDNpshQD4e-ISI0DCAZxEz5S0ABUJ9AHQYARgCt6GowAFADeKKCgpPQAbvSkAIwAXK7uXn4BwWEREVGxpABMyW4Maf6BoeHZEfoCA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Static, Type } from \"@sinclair/typebox\"\r\n\r\nexport type Input = Static\u003ctypeof Input>\r\nexport const Input = Type.Object({\r\n level1: Type.Object({\r\n level2: Type.Object({\r\n foo: Type.String(),\r\n })\r\n })\r\n})\r\n\r\nexport type Output = Static\u003ctypeof Output>\r\nexport const Output = Type.Object({\r\n level1: Type.Object({\r\n level2: Type.Object({\r\n foo: Type.String(),\r\n bar: Type.String(),\r\n })\r\n })\r\n})\r\n\r\n// The following functions should all report errors for the return value, however the first does not.\r\n\r\nfunction problematicFunction1(ors: Input[]): Output[] {\r\n return ors; // \u003c-- this does not error \r\n}\r\n\r\nfunction problematicFunction2\u003cT extends Output[]>(ors: Input[]): T {\r\n return ors; // \u003c-- ... but this does\r\n}\r\n\r\nfunction problematicFunction3(ors: (typeof Input.static)[]): Output[] {\r\n return ors; // \u003c-- ... and so does this\r\n}\r\n```\r\n\r\n\r\n### 🙁 Actual behavior\r\n\r\nFirst function does not report an error\r\n\r\n### 🙂 Expected behavior\r\n\r\nAll functions should report errors\r\n\r\n### Additional information about the issue\r\n\r\nI get the feeling this may have something to do with TypeBox's implementation of `Static\u003cT>` and where TypeScript may be implementing some optimizations around certain forms of computed / evaluated types (but not sure). TypeBox currently implements `Static\u003cT>` as follows.\r\n\r\n```ts\r\ntype Static\u003cT extends TSchema, P extends unknown[] = []> = (T & { params: P; })[\"static\"]\r\n```\r\nBy removing the intersection of P, TypeScript correctly asserts the `problematicFunction1` return type.\r\n```ts\r\ntype Static\u003cT extends TSchema, P extends unknown[] = []> = T[\"static\"] // this is fine\r\n```\r\n\r\n\r\n","author":{"url":"https://github.com/sinclairzx81","@type":"Person","name":"sinclairzx81"},"datePublished":"2023-10-17T16:42:35Z","url":"https://github.com/microsoft/TypeScript/issues/56138"}
| 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:acaa3eb6-978c-080f-c3c8-565520b393c1 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BBE0:8AE25:693AA2:8B8766:6B01A706 |
| html-safe-nonce | 03fca36e422e872311060dee8cdf59aa4d00c083425618644e02a48b8745e147 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQkUwOjhBRTI1OjY5M0FBMjo4Qjg3NjY6NkIwMUE3MDYiLCJ2aXNpdG9yX2lkIjoiODQ3MjU3MjYzNjc0NzExNDI0NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5ee6df938f11bed3d2b87e2ef483b330a0c2a5e9f60442811495366252cf6f58 |
| hovercard-subject-tag | issue:1947839321 |
| 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/56138/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f0292e22effe4a2d5c926f173ec729ded014745d155b4f6ff63c943763242f71/microsoft/TypeScript/issues/56138 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f0292e22effe4a2d5c926f173ec729ded014745d155b4f6ff63c943763242f71/microsoft/TypeScript/issues/56138 |
| og:image:alt | 🔎 Search Terms inference, deeply nested, no error, type evaluation, typebox, hkt 🕗 Version & Regression Information Hi, I've come across some unusual behavior where TypeScript seems to be skipping ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sinclairzx81 |
| 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