#type narrowing (see the link, easy example)
5 messages · Page 1 of 1 (latest)
I NEED to use record tho
I must not make a function, right side of the record I would write manually
Preview:```ts
type fruit = "banana" | 'apple' | 'michael jordan'
const fruitTexts: Record<F in fruit, (fruitName: F) => string> = {
"michael jordan": (fruitName) => ${fruitName} is awesome,
"apple": (fruitName) => ${fruitName} is SO BAD,
"banana": (fruitName) => I have allergy to ${fruitName},
}```
nevermind, I figured in out ✅
type Fruit = "banana" | 'apple' | 'michael jordan'
const fruitTexts: {[K in Fruit]: (fruitName: K) => string} = {
"michael jordan": (fruitName) => `${fruitName} is awesome`,
"apple": (fruitName) => `${fruitName} is SO BAD`,
"banana": (fruitName) => `I have allergy to ${fruitName}`,
}