-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Description
Bug Report
π Search Terms
indexed access types
π Version & Regression Information
Not a regression
β― Playground Link
π» Code
enum Type {
A = 'a',
B = 'b'
}
interface One {
type: Type.A;
x: number;
}
interface Two {
type: Type.B;
y: string;
}
type Both = One | Two;
type GetByType<T extends Type> = Extract<Both, {type: T}>;
const mapper: {[P in Type]: (val: GetByType<P>) => boolean} = {/* ... */};
// Doesn't work :(
const getIt = <T extends Both>(b: T) => mapper[b.type](b);
// Works?
const getIt2 = <T extends Type>(b: T, c: GetByType<T>) => mapper[b](c);
// Doesn't work :(
const getIt3 = <T extends Type>(b: GetByType<T>) => mapper[b.type](b);
π Actual behavior
getIt
and getIt3
doesn't compile although somehow getIt2
compiles.
π Expected behavior
All three examples should compile or at least getIt3
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed