You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interfaceExotic{id: string}typeWithoutExotic<PextendsRecord<string,unknown>={}>=Omit<P,'id'>typeWithExotic<PextendsRecord<string,unknown>={}>=WithoutExotic<P>&Exoticfunctionfn<PextendsRecord<string,unknown>>(args: WithExotic<P>): WithoutExotic<P>{const{ id, ...rest}=argsreturnrest// errors, not assignable}
π Actual behavior
Error occurs at line 12. First line in error message says Type 'Omit<WithExotic<P>, "id">' is not assignable to type 'WithoutExotic<P>'., however, second line shows Type 'Exclude<keyof P, "id">' is not assignable to type 'Exclude<Exclude<keyof P, "id">, "id">'., the assignment direction described is reverse.
Type 'Omit<WithExotic<P>, "id">' is not assignable to type'WithoutExotic<P>'.
Type 'Exclude<keyof P, "id">' is not assignable to type'Exclude<Exclude<keyof P, "id">, "id">'.
Type 'keyof P' is not assignable to type'Exclude<Exclude<keyof P, "id">, "id">'.
Type 'string | number | symbol' is not assignable to type'Exclude<Exclude<keyof P, "id">, "id">'.
Type 'string' is not assignable to type'Exclude<Exclude<keyof P, "id">, "id">'.
Type 'keyof P' is not assignable to type'Exclude<keyof P, "id">'.
π Expected behavior
There should be no error. Omit<WithExotic<P>, "id"> is assignable to type WithoutExotic<P>. Because Omit<Omit<P, K>, K> is equivalent to Omit<P, K> when P and K stay the same.
Better error messages. The assignment direction of first two error messages is reverse, it should not happened in typescript which allow variance.
The text was updated successfully, but these errors were encountered:
This appears to be a duplicate of issue #37768, which is categorized as a bug. However, I believe it may be more of a design limitation. A similar issue is discussed in #43846, classified as a design limitation, and in #28884, classified as a feature request. So I'm uncertain as to the fate of this issue.
The root problem in all of these cases is that TypeScript struggles to infer much about conditional types that depend on generic type parameters, even in situations where it seems obvious to human developers. Unlike humans, who can reason abstractly and understand the meanings of words like "Exclude" and "Omit," the compiler must rely on a heuristic algorithm that is designed to meet performance constraints.
Bug Report
π Search Terms
nested Omit, util type
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
Error occurs at line 12. First line in error message says
Type 'Omit<WithExotic<P>, "id">' is not assignable to type 'WithoutExotic<P>'.
, however, second line showsType 'Exclude<keyof P, "id">' is not assignable to type 'Exclude<Exclude<keyof P, "id">, "id">'.
, the assignment direction described is reverse.π Expected behavior
Omit<WithExotic<P>, "id">
is assignable to typeWithoutExotic<P>
. BecauseOmit<Omit<P, K>, K>
is equivalent toOmit<P, K>
when P and K stay the same.The text was updated successfully, but these errors were encountered: