Updated: 03 September 2023

1
const bobs = ['bob', 'Bob', 'BOB', 'boB'] as const
2
3
type Bob = typeof bobs[number]
4
5
const isBobKindOf = (thing: string): boolean => bobs.includes(thing as Bob)
6
7
const isBob = (thing: string): thing is Bob => bobs.includes(thing as Bob)
8
9
const people = ['bob', 'smith', 'boB', 'smITH']
10
11
const bobPeople = people.filter(isBobKindOf)
12
const bobPeople2 = people.filter(isBob)
13
14
const isKindOfFirstBob = people.find(isBobKindOf)
15
const firstBob = people.find(isBob)
16
17
const first = people[0]
18
19
if (isBob(first)) {
20
console.log(first)
21
} else {
22
console.log(first, 'not bob')
23
}