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