#type narrowing (see the link, easy example)

5 messages · Page 1 of 1 (latest)

lusty hemlock
#

I do not understand how to "extract" the current entry from a Record

#

I NEED to use record tho

#

I must not make a function, right side of the record I would write manually

restive dirgeBOT
#
piscopancer#0

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},
}```

lusty hemlock
#

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}`,
}