Created
November 25, 2020 14:07
-
-
Save ryanwilsonperkin/a36674cee7ee599a761562b2fffa3b20 to your computer and use it in GitHub Desktop.
TS Type-safe tester for __typename on a GraphQL object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface TypenameObject { | |
__typename: string; | |
} | |
function isType<O extends TypenameObject, T extends O['__typename']>(obj: O, typename: T): boolean { | |
return obj.__typename === typename; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment