TypeScript Version: 4.0.3
Search Terms:
Code
// @ts-check
/**
* @param {string} x
* @returns {number | null}
*/
const nullableFunc = (x) => {
if (/\d+/.test(x)) { return Number(x) }
return null
}
const a = nullableFunc('123')
Expected behavior:
The type of a should be number | null
Actual behavior:
The type of a is number only
VS code


Playground Link:
playground
Related Issues: