Closed
Description
TypeScript Version: 3.7-beta
Search Terms: inference, generic functions
Code
export function foo<T, K>(props: {
seed: T;
producer: (x: T) => K;
consumer: (data: K) => void;
}) {
//
}
foo({
seed: "foo",
producer: (seed) => {
// type of `seed` is string
return seed;
},
consumer: (data) => {
// type of `data` is unknown
}
})
Expected behavior: TypeScript infers K
to a string
, so the type of data
is string
.
Actual behavior: data
variable is unknown
.