-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
By DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadDeprecated - use "Working as Intended" or "Design Limitation" instead
Description
User defined type guards work perfectly well for classic function statements, as in the release notes:
interface Animal {name: string; }
interface Cat extends Animal { meow(); }
function isCat(a: Animal): a is Cat {
return a.name === 'kitty';
}
However, it appears that the arrow function equivalent isn't acceptable:
// Doesn't compile
var isReallyCat: (a: Animal) => a is Cat = (cat) => cat.name === 'kitty';
This gives "Type '(cat: Animal) => boolean' is not assignable to type '(a: Animal) => a is Cat'. Signature '(cat: Animal): boolean' must have a type predicate". I'm not clear how I would give that arrow function a 'type predicate', beyond what's already included here.
Is there a good reason for this? I can't seem to find it documented anywhere.
Metadata
Metadata
Assignees
Labels
By DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadDeprecated - use "Working as Intended" or "Design Limitation" instead