const localAuth = async (callback: () => any) => {
// not sure the return type of callback, so cast a any type
const ok = Math.random()
if (ok > 0.5)
return callback()
else {
return null
}}
localAuth(() => null).then(val => {
console.log(val.mayNotExist) // doesn't complain, but val maybe null!
})
The typescript code is as above, because the return type of callback is not sure, so I assigned it a any type, but apparently any type swallows the 'null path', how to change the code to not miss the null possibility?