DEV Community

Discussion on: Generic type guard in Typescript

Collapse
 
skwny profile image
Dane Schoonover

Is this possible to make work for interfaces? E.g. typeGuard(obj, My_Interface) ?

Collapse
 
krumpet profile image
Ran Lottem

It's possible, but this universal type guard would have to have access to some type guard function specific to that interface. This could be done with some 'type guard dictionary's or by passing a function.