Closed
Description
TypeScript Version: 3.2.0-dev.20181110
Search Terms: Pick preserve optional union
Code
type A = {
optional?: string;
other: string;
}
type B = {
optional?: string;
other: string;
}
type SimplePick = Pick<A, 'optional'>
/*
{
optional?: string | undefined;
}
*/
type PickUnion = Pick<A | B, 'optional'>
/*
{
optional: string | undefined; // <--- note it is not optional
}
*/
type A = {
optional?: string;
other: string;
}
type B = {
optional?: string;
other: string;
}
let good: SimplePick = {}; // works just fine
let fails: PickUnion = {}; // Property 'optional' is missing in type '{}'.
Expected behavior:
Pick
should preserve optional property when used on unions
Actual behavior:
It doesn't
Playground Link: link