-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Closed
Copy link
Description
TypeScript Version: 3.7.0-dev.20190928
Search Terms: Pick, union bug, pick union bug
Code
interface A {
type: 'A';
inner: {
a: boolean,
};
detail: string;
}
interface B {
type: 'b';
inner: {
b: boolean,
};
detail: string;
}
type Combined = A | B;
// Broken - typescript does not raise an error, despite the mismatch between type 'A' and inner 'b'
type DescriptionBroken = Pick<Combined, 'type' | 'inner'>;
let obj: DescriptionBroken = {type: 'A', inner: {b: true}};
// OK - typescript raises an error.
type DescriptionOk = Pick<A, 'type' | 'inner'> | Pick<B, 'type' | 'inner'>;
let objOk: DescriptionOk = {type: 'A', inner: {b: true}};
Expected behavior:
The let obj
line under the // Broken
comment should raise an error, but does not.
Actual behavior:
The let obj
line under the // Broken
comment does not raise an error, presumably due to a disassociation between the 'type' and 'inner' elements.
Related Issues: I found a number relating to Pick, but none with such a clean example or this exact issue. Maybe #33568?
Metadata
Metadata
Assignees
Labels
No labels