# Bug Report ### π Search Terms infer, Exclude, conditional typing ### π Version & Regression Information - This changed between versions 3.8.3 and 3.9.7 ### β― Playground Link [Playground link with relevant code](https://www.typescriptlang.org/play?ts=3.9.7#code/C4TwDgpgBAyglgWzAGzgMxAHgCoD4oC8UA3gNoDSEI240cAdlANZUD2aU2AugFycVUakLgF8A3AFgAUNNCQorMMDit6AQ2SUQAZxxQIAD2AR6AE20KARgCsIAY2D4ixaVDdRSTKA2ZsO3PgBXMwg0BghTfSMTc34mLigAfmYoPnoIADcIACdJKRFPP04uPOkAegAqWVoobIgAR0C4OtMtXWwo4zMLVht7R0ISVw8vHxYQdmKgkLD0yMMu2OxPBOT0rOzU5jyC8cnuPIqy6Wr5OsbmiLa9BZievocnKABRAztkQNMITD3-ABoFEoVOpNFR2rhcKUpIYwKxssAoHJoGpTKYAIqBCDaZSqACyamyTHanTuVlsj0GLik7hG3kYihxIOueC4iT4y3iOygADIhtT3J46bUGk0WszcLw4iVpOITlIkVAAFqsUwAJTUAHcYAALNTyZzDNyePjY7IMADmkuVpiE3zU9BAkJlUIYxmyaDUdmg1ttmAA8oFgGBA-gqW4APpIvgBoOBnZy6SunIer1KlV+h7ATDDDq3bpptWanV6iB-YYx4MIojwJCoDDZ-luMM02k+BnAjTi1nslZ5GkiHl8lutxjnUVXME4CU9zmGqAiYa4aT4POxH20f2Byuh4Z1FGqZAgKDh7S6yDs+MyeU1XEgDPkrN4Qa56L5633-qYBhoHJQACqS78skf4km+KrqlqZ4QHOwFzmkmQ5MM8EbHkQA) ### π» Code ```ts type Simplify<T> = {[KeyType in keyof T]: T[KeyType]}; type optionalKeys<T extends object> = { [k in keyof T]: undefined extends T[k] ? k : never; }[keyof T]; type requiredKeys<T extends object> = Exclude<keyof T, optionalKeys<T>>; export type addQuestionMarks<T extends object> = { [k in optionalKeys<T>]?: T[k]; } & { [k in requiredKeys<T>]: T[k]; }; type ZodRawShape = { [k: string]: ZodType<any>; }; interface ZodType<Output> { _type: Output; } interface ZodObject< T extends ZodRawShape, Output = Simplify< { [k in optionalKeys<T>]?: T[k]; } & { [k in requiredKeys<T>]: T[k]; } > > extends ZodType<Output> { readonly _shape: T; } type MyObject<T> = T extends ZodObject<infer U> ? U extends ZodRawShape ? U : never : never; ``` ### π Actual behavior `infer U` causes an error with `requiredKeys` using `Exclude` utility type: > Type 'U' does not satisfy the constraint 'ZodRawShape'.(2344) The same inference works when `requiredKeys` is simplified to: ```ts type requiredKeys<T extends object> = { [k in keyof T]: undefined extends T[k] ? never : k; }[keyof T]; ``` The problem disappears when some type manipulations (`Simplify`, `k in optionalKeys<T>`, `k in requiredKeys<T>`) are removed. ### π Expected behavior Both `requiredKeys` implementations are expected to work similarly.
Activity
RyanCavanaugh commentedon Feb 28, 2022
Wanted: a shorter repro to produce a constraint violation on a
T<infer U>expressionRyanCavanaugh commentedon Feb 28, 2022
This is as good as I can get it:
The lack of error elaboration here is particularly frustrating