You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Type guard function does not work for string literal types #7441
typeClick='click';functionisClick(event: string): event is Click{returnevent==='click';}functionvalidateClickEvent(event: string): Click{if(isClick(event)){returnevent;// this line raises a compilation error: Type 'string' is not assignable to type '"click"'}thrownewError('not click');}typeCreature={};typeAnimal={}&Creature;functionisAnimal(creature: Creature): creature is Animal{returntrue;}functionvalidateAnimalCreature(creature: Creature): Animal{if(isAnimal(creature)){returncreature;// this line does not raise any compilation error}thrownewError('not animal');}
Activity
DanielRosenwasser commentedon Mar 9, 2016
Related to #7224, and a fix exists at #7235.
Merge pull request #7235 from weswigham/narrow-all-types
sandersn commentedon Jun 2, 2016
Fixed by #7235