π Search Terms
incorrect generic resolution
π Version & Regression Information
I don't think this is caused by a new update.
β― Playground Link
https://tsplay.dev/weG9Xm
π» Code
export interface Item1 { kind: "item1" }
export interface Item2 { kind: "item2" }
export interface Item3 { kind: 'item3' }
export type Item = Item1 | Item2
const Guard1 = (o: unknown): o is Item => true
const Guard2 = <M extends Item>(o: M | Item3): o is M => true
export function Test1<M extends Item>(src: M | Item3) {
if (!Guard1(src)) {
// these are flipped :
src // Item3 | M
src.kind // item3
}
if (!Guard2(src)) {
// and so are these :
src // Item3
src.kind // "item1" | "item2" | "item3"
// And src isn't even typeof src :
const test: typeof src = src;
// Type 'Item1 | Item2 | Item3' is not assignable to type 'Item3'.
}
}
π Actual behavior
Looks like there's two resolvers that come up with opposing results, and both are used.
π Expected behavior
Consistent type resolution.
Edit: or potentially an error message to indicate it's not resolvable.
Additional information about the issue
No response
π Search Terms
incorrect generic resolution
π Version & Regression Information
I don't think this is caused by a new update.
β― Playground Link
https://tsplay.dev/weG9Xm
π» Code
π Actual behavior
Looks like there's two resolvers that come up with opposing results, and both are used.
π Expected behavior
Consistent type resolution.
Edit: or potentially an error message to indicate it's not resolvable.
Additional information about the issue
No response