0

I came across some function declaration like below.


type DataType = TypeA | TypeB | TypeC;

function Func(data: DataType): data is TypeA {
...
}

I don't understand the is part of the declaration. How it affects the return type of the function?

David S.
  • 10,578
  • 12
  • 62
  • 104
  • 1
    It's a [user-defined type guard](https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types) – VLAZ Jun 21 '20 at 22:58
  • Also relevant: [Interface type check with Typescript](https://stackoverflow.com/q/14425568) [How to get a variable type in Typescript?](https://stackoverflow.com/q/35546421) [Typescript: Check “typeof” against custom type](https://stackoverflow.com/q/51528780) – VLAZ Jun 21 '20 at 23:04

1 Answers1

0

This Stackoverflow post might help you understand the is keyword a little better.

itsanewabstract
  • 1,006
  • 3
  • 12