Open pakoito opened 2 years ago
I think it has nothing to do with enums. A shorter repo here:
type IsOne<T> = T extends 1 ? true : false;
type Wrapped<T> = { data: IsOne<T> };
type V1 = IsOne<number> extends IsOne<1> ? true : false;
// ^?
// type V1 = false, expected
type V2 = { data: IsOne<number> } extends { data: IsOne<1> } ? true : false;
// ^?
// type V2 = false, expected
type V3 = Wrapped<number> extends Wrapped<1> ? true : false;
// ^?
// type V3 = true, bug?
It looks like we're not measuring the variance of Container
correctly due to R
only appearing in conditional type test positions.
Two possible workarounds:
interface Container<out R extends ToRefine> {
option: Refine<R>;
}
or
type Refine<R extends ToRefine> = { [ToRefine.One]: number; [ToRefine.Two]: string }[R];
Bug Report
🔎 Search Terms
Enum refinement, enum unification, enum constant,
🕗 Version & Regression Information
3.3 and up, as far back as I could test it
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
callRefined
fails to typecheck due to a type mismatch as expectedcallContained
passes the typechecker when it shouldn't🙂 Expected behavior
Both
callRefined
andcallContained
should fail to typecheck