DEV Community


Discussion on: Generic type guard in Typescript

skwny profile image
Dane Schoonover

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

krumpet profile image
Ran Lottem Author

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.