I'm using Typescript 3.2.2 and unable to achieve the most basic implementation of type guards:
interface Bird {
fly(): boolean;
}
interface Fish {
swim(): boolean;
}
function swimIfYouCan(x: Fish | Bird) {
if ((<Fish>x).swim) {
return true
}
}
This produces Error:(50, 11) TS2693: 'Fish' only refers to a type, but is being used as a value here.
in WebStorm and SyntaxError: /Users/sea-kent/git/docket-management/webapp/src/App.tsx: Unexpected token (51:8)
from yarn
. Is there a configuration needed to enable this syntax?
<Fish>
could be an element - usex as Fish
instead. See e.g. stackoverflow.com/a/54614279/3001761, typescriptlang.org/docs/handbook/jsx.html – jonrsharpe