-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3.5 Breaks function assignments that use a complex Discriminated Unions Type #31833
Comments
Indexed access type + contravariance + inferred intersection = #30769, I'd wager. |
Fix up: #31837 |
Here is a smaller repro. // You need the two aliases to avoid variance measurements.
type A1 = <
T extends { x: number, y: string } | { x: boolean, y: number}
>(
x: T["x" | "y"]
) => void
type A2 = <
T extends { x: number, y: string } | { x: boolean, y: number}
>(
x: T["x" | "y"]
) => void
declare const a: A1;
let b: A2 = a; // error, even though A1 and A2 are identical. Another interesting case: type Obj = { x: number, y: string } | { x: boolean, y: number};
function fun<T extends Obj>(l: { x: T["x" | "y"] }, r: { x: T["x" | "y"] }) {
l = r; // was ok, now error
} |
oof, just bonked into this with code like interface A {
k: "a";
v: string
}
interface B {
k: "b";
v: number
}
interface I {
method<K extends "a" | "b">(
k: K,
v: Extract<A | B, { k: K }>["v"]
): void;
}
class C implements I {
method<K extends "a" | "b">( // error!
//~~~~ Type 'Extract<A, { k: K; }>["v"]' is not assignable to
// type 'Extract<A, { k: K; }>["v"] & Extract<B, { k: K; }>["v"]'.
k: K,
v: Extract<A | B, { k: K }>["v"]
) { }
} |
No longer errors, though jcalz's still does. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TypeScript Version: 3.4.5
Search Terms: Discriminated Unions Type, Function, Assignment, Type Property
Code
Worked for a long time, but
3.5.1
breaks it. it hasn't been fixed onnext
. I tried3.6.0-dev.20190608
.Interestingly, it breaks only on
extra
and not on the type itself. meaning that if I changeFooExtraFromType
toFooFromType
it works.If I use
typeof
instead of writing the signature it works. this is really weird as they are the exact same signature.Expected behavior:
Compile as it had been working up to
3.4.5
.Actual behavior:
Playground Link: Doesn't break on playground, I guess the version is old.
The text was updated successfully, but these errors were encountered: