hello, let say I have function example, that returns either string or number based on boolean passed via parameter.
/**
* @template {boolean} T
* @param {T} bool
* @returns {T extends true ? string : number}
*/
function example(bool) {
return bool ? '1' : 1;
}
const x = example(true);
const y = example(false);
in this case, x has correct type string, and y has correct type number. But inside of function implementation it throws error:
Type 'string | number' is not assignable to type 'T extends true ? string : number'.