-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discriminated Unions with a common partially optional property #44689
Comments
|
It is unrelated to discriminated unions or optional property. A minimal repo: interface B {
b: number;
}
interface C {
c: number;
}
type Union = B | C;
const test1: B = { b: 4, c: 4 }; // Error as expected, because of excess property check.
const test2: C = { b: 4, c: 4 }; // Error as expected, because of excess property check.
const test3: Union = { b: 4, c: 4 }; // No error. See #20863 type UnionKeys<T> = T extends T ? keyof T : never;
type StrictUnionHelper<T, TAll> = T extends any ? T & Partial<Record<Exclude<UnionKeys<TAll>, keyof T>, undefined>> : never;
type StrictUnion<T> = StrictUnionHelper<T, T>
const test4: StrictUnion<B | C> = { b: 4, c: 4 }; // Error as expected. |
@whzx5byb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug Report
π Search Terms
Discriminated Unions with a common partially optional property
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
test4
is displayed as valid.π Expected behavior
test4
should not be valid.The text was updated successfully, but these errors were encountered: