-
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 fixedFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Description
Bug Report
π Search Terms
generics overload
π Version & Regression Information
- 4.7.4(current), 4.8.0-beta(beta)
β― Playground Link
Playground link with relevant code
π» Code
type A1<T> = { type: "a1", v: T };
type B1<T> = { type: "b1", v: T };
type A2 = { a2: string };
type B2 = { b2: string };
function fn<T>(p1: (pp1: 0) => A1<T>, p2: (pp2: A2) => 0): void;
function fn<T>(p1: (pp1: 0) => B1<T>, p2: (pp2: B2) => 0): void;
function fn<T>(
p1:
| ((pp1: 0) => A1<T>)
| ((pp1: 0) => B1<T>),
p2:
| ((pp2: A2) => 0)
| ((pp2: B2) => 0)
) {}
const valA1: A1<string> = ({ type: "a1", v: "" });
const valB1: B1<string> = ({ type: "b1", v: "" });
// expect A
fn((ap1) => valA1, (ap2) => 0);
fn((ap1) => valA1, (ap2: A2) => 0);
fn((ap1) => valA1, (ap2: any) => 0);
fn((ap1) => valA1, (ap2: unknown) => 0);
fn((ap1: 0) => valA1, (ap2) => 0);
// expect B
fn((bp1) => valB1, (bp2) => 0); // but it will be A, only this will result in an error
fn((bp1) => valB1, (bp2: B2) => 0);
fn((bp1) => valB1, (bp2: any) => 0);
fn((bp1) => valB1, (bp2: unknown) => 0);
fn((bp1: 0) => valB1, (bp2) => 0);
π Actual behavior
No overload matches this call.
Overload 1 of 2, '(p1: (pp1: 0) => A1<string>, p2: (pp2: A2) => 0): void', gave the following error.
Type 'B1<string>' is not assignable to type 'A1<string>'.
Types of property 'type' are incompatible.
Type '"b1"' is not assignable to type '"a1"'.
Overload 2 of 2, '(p1: (pp1: 0) => B1<string>, p2: (pp2: B2) => 0): void', gave the following error.
Argument of type '(bp2: A2) => 0' is not assignable to parameter of type '(pp2: B2) => 0'.
Types of parameters 'bp2' and 'pp2' are incompatible.
Property 'a2' is missing in type 'B2' but required in type 'A2'.(2769)
π Expected behavior
No errors
jcalz
Metadata
Metadata
Assignees
Labels
Design LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixedFix AvailableA PR has been opened for this issueA PR has been opened for this issue