function f(x:boolean|string) { return x }
f(true) // boolean | string
Run Code Online (Sandbox Code Playgroud)
为什么打字稿不能理解返回值是一个布尔值?
function f(x:boolean|string) {
return typeof x === 'boolean' ? true : 'str'
}
f(true) // boolean | string
Run Code Online (Sandbox Code Playgroud)
它也无法理解.
我是否需要手动设置函数重载定义?
typescript ×1