-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Regression of incorrect literal inference in generic function in 3.4 #31443
Copy link
Copy link
Closed
Description
TypeScript Version: 3.4.1 ... 3.4.5, 3.5.0-dev.20190517
Search Terms: enum is not assignable to type
Code
class M<T>
{
}
function test<V>(m: M<V>, f: () => V)
{
}
enum Enum
{
A,
B,
}
class ClassWithConvert<T>
{
constructor(init: T)
{
}
convert<U>(converter: { to: (v: T) => U; from: (v: U) => T; })
{
}
}
const m2 = new M<ClassWithConvert<Enum>>();
test(m2, () => new ClassWithConvert(Enum.A));Expected behavior:
no errors
Actual behavior:
Error:
Type 'ClassWithConvert<Enum.A>' is not assignable to type 'ClassWithConvert<Enum>'.
Type 'Enum' is not assignable to type 'Enum.A'.
Playground Link (Note: Option strictFunctionTypes must be checked!)
Related Issues:
These issues look similar: #31204 #28102
When I tried to compile with typescript@next (3.5.0-dev.20190517) I've got more detailed error description:
error TS2322: Type 'ClassWithConvert<Enum.A>' is not assignable to type 'ClassWithConvert<Enum>'.
Types of property 'convert' are incompatible.
Type '<U>(converter: { to: (v: Enum.A) => U; from: (v: U) => Enum.A; }) => void' is not assignable to type '<U>(converter: { to: (v: Enum) => U; from: (v: U) => Enum; }) => void'.
Types of parameters 'converter' and 'converter' are incompatible.
Type '{ to: (v: Enum) => any; from: (v: any) => Enum; }' is not assignable to type '{ to: (v: Enum.A) => any; from: (v: any) => Enum.A; }'.
Types of property 'from' are incompatible.
Type '(v: any) => Enum' is not assignable to type '(v: any) => Enum.A'.
Type 'Enum' is not assignable to type 'Enum.A'.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScript