`Type assertion`은 [[Type predicates]]와 비슷한 기능을 하는데 `Type assertion` 다음의 코드에선 [[Union]]타입을 구성하는 요소 중의 하나의 타입으로 추론된다.
예를 들어보면,
```typescript
function assertDog(creature: User | Dog): asserts creature is Dog {
if (creature.howl === undefined) {
throw new Error("creature is not a dog")
}
}
const creature: User | Dog = {howl: () => {}}
assertDog(creature)
creature.howl()
```
`Type assertion` 작성법은 [[Type predicates]]와 유사한데 차이점은 `asserts (매개 변수) is (타입)` 형태로 코드를 작성하고 **반드시 함수에서 리턴하는 타입은 void 이어야 한다.**
위의 예제에서 `type assertion` 함수 실행 후 다음 줄부터는 `creature`는 `Dog`로 추론이 된다.
---
참조 강의: https://inf.run/FVDi