TypeScript Version: 2.1.4
Code
function or<A, B>(a: A, b: B) {
if (Math.random() < 0.5) return {value: a}
else return {value: b}
}
function readValue<T>({value}: {value: T}) {
return value
}
const numeric1 = or(1, '1')
const v = readValue(numeric1)
Expected behavior:
Compiled with no error.
Actual behavior:
Error on readValue call:
The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Workaround:
Explicitly add return type or<A, B>(): {value: A | B}.
TypeScript Version: 2.1.4
Code
Expected behavior:
Compiled with no error.
Actual behavior:
Error on
readValuecall:The type argument for type parameter 'T' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Workaround:
Explicitly add return type
or<A, B>(): {value: A | B}.