-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Description
This is the simplest version of this bug I could find:
function example<T1>() {
let x = {
foo: <T2>(t2: T2) => x,
bar: (t1: T1) => x
}
return x;
}
example<number>()
.foo("hello")
.bar(1) // Argument of type 'number' is not assignable to parameter of type 'T1'
The call to bar
fails to compile. The type is example<number>
, so it should compile.
If I try to add type information to x
, another compilation error occurs:
type Example<T1> = {
foo: <T2>(t2: T2) => Example<T1>,
bar: (t1: T1) => Example<T1>
}
function example<T1>() {
let x: Example<T1> = {
foo: <T2>(t2: T2): Example<T1> => x,
bar: (t1: T1): Example<T1> => x
}
return x;
}
example<number>()
.foo("hello")
.bar(1)
Type '{ foo: (t2: T2) => Example; bar: (t1: T1) => Example; }' is not assignable to type 'Example'.
Types of property 'foo' are incompatible.
Type '(t2: T2) => Example' is not assignable to type '(t2: T2) => Example'.
Type 'Example' is not assignable to type 'Example'.
Types of property 'bar' are incompatible.
Type '(t1: T1) => Example' is not assignable to type '(t1: T1) => Example'.
Types of parameters 't1' and 't1' are incompatible.
Type 'T1' is not assignable to type 'T1'.
let x: Example
Interestingly, removing either the foo
or bar
methods will allow the code to successfully compile:
type Example<T1> = {
foo: <T2>(t2: T2) => Example<T1>,
//bar: (t1: T1) => Example<T1>
}
function example<T1>() {
let x: Example<T1> = {
foo: <T2>(t2: T2): Example<T1> => x,
//bar: (t1: T1): Example<T1> => x
}
return x;
}
type Example<T1> = {
//foo: <T2>(t2: T2) => Example<T1>,
bar: (t1: T1) => Example<T1>
}
function example<T1>() {
let x: Example<T1> = {
//foo: <T2>(t2: T2): Example<T1> => x,
bar: (t1: T1): Example<T1> => x
}
return x;
}