1

Assume I have two types:

type Season = 'WINTER' | 'SUMMER';
type Activity = 'SKIING' | 'SNOWBOARDING' | 'SWIMMING' | 'SUNBATHING' 

and also

seasonActivities: Record<Season, Activity []> = {
WINTER = ['SKIING', 'SNOWBOARDING'],
SUMMER = [ 'SWIMMING', 'SUNBATHING']
}

Is there any way of using the type system to guarantee that seasonActivities contains all possible values of Activity?

Is there any way of using the type system to guarantee that seasonActivities does not contain duplicate values of Activity?

Lamora
  • 85
  • 4
  • This is really two questions, but the answer to both of these is "you can use the type system to discourage repeated/missing elements but it's not particularly pretty". See the answers to the linked questions for more information. – jcalz Aug 12 '22 at 20:51

0 Answers0