Closed dminkovsky closed 4 years ago
Actually, looks like it works if I write a user-defined type guard:
declare function doSomethingWithCode(code: Code) {}
declare function doSomethingWithToken(token: Token) {}
function isCode(codeOrToken: CodeOrToken) : codeOrToken is Code {
return !!codeOrToken.code;
}
function doSomething(codeOrToken: CodeOrToken) {
isCode(codeOrToken)
? doSomethingWithCode(codeOrToken)
: doSomethingWithToken(codeOrToken);
}
No errors.
Thanks a lot for this packaging this up! :)
Not sure if this is a bug. This type works as intended for assignment. However:
The last line has the TS error:
Likewise:
Produces the error:
Can anything be done about this?