Title: Generics in conditionals have differing behavior in 4.8 · Issue #49490 · microsoft/TypeScript · GitHub
Open Graph Title: Generics in conditionals have differing behavior in 4.8 · Issue #49490 · microsoft/TypeScript
X Title: Generics in conditionals have differing behavior in 4.8 · Issue #49490 · microsoft/TypeScript
Description: TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - Generics in conditionals have differing behavior in 4.8 · Issue #49490 · microsoft/TypeScript
Open Graph Description: TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - Generics in conditionals have differing behavior in 4.8 · Issue #49490 · microsoft/TypeScript
X Description: TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - Generics in conditionals have differing behavior in 4.8 · Issue #49490 · microsoft/TypeScript
Opengraph URL: https://github.com/microsoft/TypeScript
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generics in conditionals have differing behavior in 4.8","articleBody":"I found a break in [zustand](https://github.com/pmndrs/zustand/) from looking at the logs of a failed NewErrors run. It might be more correct, but figured it was worth noting.\r\n\r\n```ts\r\nexport type Store\u003cT extends object> = {\r\n setState: (x: T) => void\r\n getState: () => T;\r\n}\r\n\r\ntype ExtractState\u003cS> = S extends { getState: () => infer T } ? T : never\r\n\r\ntype Extractable\u003cS extends Store\u003cobject>> = {\r\n getServerState?: () => ExtractState\u003cS>\r\n}\r\n\r\nexport function f\u003cTState extends object>(api: Extractable\u003cStore\u003cTState>>) {\r\n// ~~~~~~~~~~~~~\r\n// Type 'Store\u003cTState>' does not satisfy the constraint 'Store\u003cobject>'.\r\n// Types of property 'setState' are incompatible.\r\n// Type '(x: TState) => void' is not assignable to type '(x: object) => void'.\r\n// Types of parameters 'x' and 'x' are incompatible.\r\n// Type 'object' is not assignable to type 'TState'.\r\n// 'object' is assignable to the constraint of type 'TState', but 'TState' could be instantiated with a different subtype of constraint 'object'.\r\n}\r\n```\r\n\r\nhttps://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/src/react.ts#L30\r\n\r\n```ts\r\nexport function useStore\u003cTState extends State, StateSlice>(\r\n api: WithReact\u003cStoreApi\u003cTState>>,\r\n// ~~~~~~~~~~~~~~~~\r\n// error TS2344: Type 'StoreApi\u003cTState>' does not satisfy the constraint 'StoreApi\u003cobject>'.\r\n```\r\n\r\nThere's a few of these.\r\n\r\nNew errors for non-composite project https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/tsconfig.json\r\n* TS2344 at https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/src/react.ts#L30\r\n\r\n ```\r\n error TS2344: Type 'StoreApi\u003cTState>' does not satisfy the constraint 'StoreApi\u003cobject>'.\r\n ```\r\n* TS2344 at https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/src/react.ts#L56\r\n\r\n ```\r\n error TS2344: Type 'Mutate\u003cStoreApi\u003cT>, Mos>' does not satisfy the constraint 'WithReact\u003cStoreApi\u003cobject>>'.\r\n ```\r\n* TS2344 at https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/src/react.ts#L59\r\n\r\n ```\r\n error TS2344: Type 'Mutate\u003cStoreApi\u003cT>, Mos>' does not satisfy the constraint 'WithReact\u003cStoreApi\u003cobject>>'.\r\n ```\r\n* TS2345 at https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/src/react.ts#L68\r\n\r\n ```\r\n error TS2345: Argument of type 'StoreApi\u003cT>' is not assignable to parameter of type 'WithReact\u003cStoreApi\u003cobject>>'.\r\n ```\r\n* TS2344 at https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/tests/context.test.tsx#L24\r\n\r\n ```\r\n error TS2344: Type 'StoreApi\u003cCounterState>' does not satisfy the constraint 'StoreApi\u003cobject>'.\r\n ```\r\n* TS2344 at https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/tests/context.test.tsx#L48\r\n\r\n ```\r\n error TS2344: Type 'StoreApi\u003cCounterState>' does not satisfy the constraint 'StoreApi\u003cobject>'.\r\n ```\r\n* TS2344 at https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/tests/context.test.tsx#L135\r\n\r\n ```\r\n error TS2344: Type 'StoreApi\u003cCounterState>' does not satisfy the constraint 'StoreApi\u003cobject>'.\r\n ```\r\n* TS2344 at https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/tests/context.test.tsx#L150\r\n\r\n ```\r\n error TS2344: Type 'StoreApi\u003cCounterState>' does not satisfy the constraint 'StoreApi\u003cobject>'.\r\n ```\r\n* TS2322 at https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/tests/middlewareTypes.test.tsx#L171\r\n\r\n ```\r\n error TS2322: Type 'StoreApi\u003cOmit\u003c{ count: number; }, never>>' is not assignable to type 'StoreApi\u003cobject>'.\r\n ```\r\n* TS2344 at https://github.com/pmndrs/zustand/blob/197e5d41993b0e3ad6ebef9a7e6a9161753072f1/tests/types.test.tsx#L86\r\n\r\n ```\r\n error TS2344: Type 'StoreApi\u003cExampleState>' does not satisfy the constraint 'WithReact\u003cStoreApi\u003cobject>>'.\r\n ```\r\n\r\n\r\n_Originally posted by @DanielRosenwasser in https://github.com/microsoft/TypeScript/issues/49488#issuecomment-1152817431_","author":{"url":"https://github.com/DanielRosenwasser","@type":"Person","name":"DanielRosenwasser"},"datePublished":"2022-06-11T00:43:53Z","url":"https://github.com/microsoft/TypeScript/issues/49490"}
| 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 | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:e359138a-54ed-5b43-9bd1-216eb296ae46 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 94A0:DB09F:1F3E6DB:27CFA7C:6B0170B7 |
| html-safe-nonce | 81afaa8f55b94f4a7e6fddfb7ea461c0e9b6f1d4bb1a2bdf3299402379c28da5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NEEwOkRCMDlGOjFGM0U2REI6MjdDRkE3Qzo2QjAxNzBCNyIsInZpc2l0b3JfaWQiOiI4NzA4NTI4MjY1ODU5NTI2ODM5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e9cb49acde12da94fcf24adb9c26866bbe5ca48beef2f149ca42752dcf7d7e77 |
| hovercard-subject-tag | repository:20929025 |
| 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/microsoft/TypeScript/issues/49490 |
| twitter:image | https://opengraph.githubassets.com/47cde802d3847ff7ce61448bd4f8c3272d012c9a3f2b9085b71a67530bf7bbd6/microsoft/TypeScript |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/47cde802d3847ff7ce61448bd4f8c3272d012c9a3f2b9085b71a67530bf7bbd6/microsoft/TypeScript |
| og:image:alt | TypeScript is a superset of JavaScript that compiles to clean JavaScript output. - Generics in conditionals have differing behavior in 4.8 · Issue #49490 · microsoft/TypeScript |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-cache |
| 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