Last active
January 24, 2020 07:04
-
-
Save sketchbuch/bd5d6616c9274d742f45bf43e78ddcdc to your computer and use it in GitHub Desktop.
TS - Typescript example of a Predicate Type Guard
This file contains 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
export interfac-e NpmContributors { | |
email?: string; | |
githubUsername?: string; | |
name: string; | |
url?: string; | |
} | |
export interface NpmMaintainer { | |
email: string; | |
name: string; | |
} | |
export const isContributor = (npmType: NpmMaintainer | NpmContributors): npmType is NpmContributors => { | |
return (npmType as NpmContributors).url !== undefined; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment