Created
January 11, 2021 15:28
-
-
Save davidcsejtei/b2e5fc4fe48e90ddd978415e493d0d4f to your computer and use it in GitHub Desktop.
Typescript usage - from pain to gain
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
| export type User = { | |
| name: string, | |
| age: number, | |
| roles: Role[]; | |
| } | |
| export function isValidUser(user: unknown): user is User { | |
| return !!(user as User).name && | |
| !!(user as User).age && | |
| !!(user as User).roles && | |
| Array.isArray((user as User).roles); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment