-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
TypeScript Version: 3.1.0-dev.20180727
Code
// ConditionalTuple could also return just [] in the false branch, issue still repros
type ConditionalTuple<T> = [T] extends [undefined] ? [] : [T];
// works fine!
declare var f1: (...args: any[]) => void;
declare var f2: <T>(...args: ConditionalTuple<T>) => void;
declare var f3: (...args: ConditionalTuple<number>) => void;
f2 = f1;
f3 = f1;
// but if we move the signatures above into a callback parameter with that signature,
// assignability breaks - the types of cb are incompatible.
declare var cb1: (cb: (...args: any[]) => void) => void;
declare var cb2: <T>(cb: (...args: ConditionalTuple<T>) => void) => void;
declare var cb3: (cb: (...args: ConditionalTuple<number>) => void) => void;
cb2 = cb1; // can't assign to cb2
cb3 = cb1; // this works thoughExpected behavior:
I am able to construct callback signatures with generic conditional types and tuples that are assignable with the maximally general callback signature (cb1).
Actual behavior:
cb1 cannot be assigned to cb2, but removing the generic parameter ala cb3 makes assignability work as expected.
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug