TypeScript Version:
1.8.2
Code
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');}Expected behavior:
Can apply type guard to string literal types.
Actual behavior:
Cannot apply type guard to string literal types.
TypeScript Version:
1.8.2
Code
Expected behavior:
Can apply type guard to string literal types.
Actual behavior:
Cannot apply type guard to string literal types.