Closed
Description
TypeScript Version: 2.9.1, 3.0.0-dev.20180602
Search Terms: conditional union type operator expansion
Code
type U =
| {
tag: 'a';
foo: number;
f(): void;
}
| {
tag: 'b';
bar: boolean;
g(): void;
};
type FilterUnion<T extends { tag: string }, K> = T extends { tag: K } ? T : never;
type StripFunctions<T> = Pick<
T,
{ [K in keyof T]: T[K] extends (...args: any[]) => any ? never : K }[keyof T]
>;
type FilterAndStrip<K extends U['tag']> = StripFunctions<FilterUnion<U, K>>;
type X1 = FilterAndStrip<'a'>;
type X2 = StripFunctions<FilterUnion<U, 'a'>>;
Expected behavior:
X1
and X2
should both have the type { tag: 'a'; foo: number }
, since the latter is just an expansion of the first.
Actual behavior:
X2
is correct, but X1: {}
.