Created
April 30, 2021 12:15
-
-
Save asci/d43919f5dbf24e5911262eb3410f9bc5 to your computer and use it in GitHub Desktop.
Typescript snippets
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
const fruits = ["apple", "banana", "cherry", "orange"] as const | |
type Fruit = typeof fruits[number] | |
const myFruit: Fruit = "cherry" | |
function isFruit(some: unknown): some is Fruit { | |
return fruits.includes(some as any) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment