Type | Treat The Finale
Tags: typescript, javascript, challenge, codenewbie
Published: 2020-10-31 18:50:09

Thank you so much for participating in TypeScript's `Type | Treat` coding challenges! Unfortunately, we have come to the end of our spooky journey but no worries, there will be more challenges to come in the future! 

## Beginner/Learner Challenges

 1. [Investigate haunting data from ghosts](https://www.typescriptlang.org/play?#code/PTAEE0HsFcHICcCmoC2BDA1gSwHYHNQ0dCAHE0AdwAssBjK0WyHHRWgFwGdR3JDQAJmnZoARmk6IAUCFCQAZqAA2kWmiWg8VSJy6EcAnlURZ4oeWgBuMeFnbIqaaDi4A6KTLBRohJIyTCuATsxoxKWIgulDT0jMysHNy8RsKCwmISiAA0nvqGAJ4woI6WyESgAIIACgCSoEicJMySmpGI8MKIhvKQZoU+Trzo7HTqSvnuuQDqxsT9oLpo8Ow88PlBPHwCWI1KaPlGDk4uQZxZoPMB4QBe0rIhqfMCzLArGDiQFMWfmzz5JMgQsgSEs0ChEPYzERDAAraC6UDw5AAAyI+WRk1kqJw6OKElAdm4JD2tGyoFE0BWaDiSiUiDQeGgyCQTBQ4IMXRSK3mahwuSRoFgNQ5AA9OQAVf6ITiwX5IFCQUqHQVo2UUOzaSmMRz4DZA3IAcW0umqNQAStKmjgWuwpZNbQDQEadOxTRbGs1kABeUAAbykoFAODBiAAXAt2LZ8AHyaYQgARToAfnDuijeBjAnpCeTqcjQRjoiwkDz6Y8gcczhG+E44Yq8A6+QAPL6eHY6aWgucSPBFZEiKTO-hzio1CNmEOCABfAB8UinHiY1pW212+2dCJ9AAotC7wxvXbV3VbJABKUBemd+mNLziQOmuFR4LfIgByIfDABJfbvdK5g+CU7IqeMZYIoO7GuwrhFssVCJvY563veiCPpAz7IgAQnGVBCPkX4-pB0HYfBiBASBgZgaAEEuq4WbCHBnSIc0yGoeh8YRAI+G-lBdE5vYZE3sxD5Pi+AA6OBYSWoDftxRGQAJgnWixInIuJ9bsBQvQYLWwExrJlYnDWrg9PAACiaD0FuSwaVpF5Xv6gaBquxL7AAEsc1Z4JwVnLJp8AYORoBTiBC65N4Zh4JA6jhvKfZGDs+j5Oc6ohDAKz0EQeAbAebqWp6Ui3iuOwufk7lVqcF5UQZnnhmi56XtegZIcJaEvqAAC0oDiu2YbSb61VBK4IzsHSAlNUJKEqY534DfgqFjsWOBjXESkteh039R5g09n26A4KSAmhUAA)

 2. [Plotting pumpkin types](https://www.typescriptlang.org/play?#code/PTAEE0HsFdQCwIYDcCmoGlQJwJ6gM4AOKAxgJYIA2oh0AtoQNZkB2ANOiwCag4ygB3BCwAuoEZFAksKBCLQYROYqABmWSHVBkRAOgBQ+kKAAqWBFx1lILKpTxFZzFgHMOfWCRiUeXFKtYFcWU0SCxtURQsVQQSFCMwVTDxODR8RGIOACNoMQ90GVAbe1AXSFYXcUlEVBSyfCKWNFoGZzYEgkl8rhsAcjFVFBRqSjJGNB1ehoEwkThQLmhCUZI5CpS0PwCWKxsDfS8WfDEWplZQAF5QAG99UClISjCALlAAIhxhp4F6uDf2+5KYivN5laBYLj-O4EMgALxQIIAsihLPQofcUE0sC4cCCAIwABgAnKAANIAKxoUVAhIJLnRam+URRrxilHwKABMPhAGFESCAKwE3QADlAAA9QAAWYUANgloAAzMKAExSOhQgC+AG5DMYAJJHeQWIqqKQyNaudDBFSjcbPBIdIFoAAK9DOLEuN1AHXuXieWFexywFV9oF0EY6msdxh5wl4-Hy0A5NpQkDNzoaEnNsnk1vwFUoaFGWIA-IZnaA3a1zldhDg9WAAHIocViJYcGQchBYEjzOCQAQJzzx5NBXJkUZKVNVeDCLhFp2pAgIOjNDRZItaH5za2qaAsEgiawsXSgAASg6k8fyrZE5iPGw6MhE4M9lfUmjqDX3h+PNlnFwUDEOY0lXNBnXLA4bGOHM5BQABRcVV2WFBqw9L0AAoAEpLgAPhuaEXzfGh3WcfRo30St0OcAAxDQ6Fog8jxPL1630IA)

 3. [Tallying Trick or Treat responses](https://www.typescriptlang.org/play?#code/PTAEE0HsFcHIDcCmoBGjEDtQGt0AcBLDAc1AENQATAsgJwE9RIAzUemW0AF1oIGNsTTj0RkuAKBChaiAM7QANl1mhmkTu2idZIxFwA03ABaJGxTIlpkFCxs2sLQRLpFCSwXIzOR8xiYuoEcgBc3DJisoY8-NgqZBiUoBiQALSyRpAA7rIAdOLuoADC8WwwoAC2ZLjG3tz0eHKgmUb8RqC+WJRyfLxoTMwFnnLIMvJKsgD8+XyQGDphosqgALygANrioKAA3qAKkL5cBLOhAEQAEjCyyACMp4ajilxnImL3C2Khux2U9GcAMscsAAhOinUAAX0h+k2Oz2BzEQLOl2g11AAGZ3o8lC9wlx3q9nnCfn9QKcALJ0FSg2jgqEQmFbXb7Q5IskotEAFixcieuMWBLxX1QVUQlDOhUgkGwQVk7xJZwASuhrrA5ZDIeIALrTWbzaICFSrDZM+Gsk7sq7IABMPLGRNOBuwgpiZ0pxH4dMZcJZiItFytoAA7Ha+WSnS6BGcAMpaPC8a6UOna3VzLhJSDRjLZFbrWHMhFHf0c5AANlDOLJyTS2eTOoKADkssYxKVoKAjGQkMZkFx6nJDB02xVRT3ygVkunKNA8Ap+H5QLBfUWMLByAlF9iuGuUIxUURSAUKNAMEDVOpN7ylGv4okKBhEJknBguJZrnwV3UGlMgA)

 4. [Stop a sneaky spooky moving things around](https://www.typescriptlang.org/play?#code/PTAEDkHsFpIOwKagNZ0gdwM6nQCwIYAuoAltgOaQlzmjwA0oARgK7ECekLohu1yoTiwBOOSMOQAHADb4AxkgBQIUtgIs4hBABNm7UPlCTI0rcPIIyhAHSgAksWTVthzCznJM15WB+gAmlyikEwAVghyhNjICAiSoBaEhNS0cgQ0OswIfHC6vEiYCoiY9H6YhJDxvGSgAGbCkAC2oASSkghwKXqgjfhONIJBdGERUaDCCPja8NLsfhWg5ZU8fNiYxpDI+kzZ+ABuJOLeioTs7aAASqPi+gC8oADeiqDjkE2YAFyXb40A2gC6z1AaDICE+Bjg7ABigAvooTmckBcfqB7k8XnB8I0EF9ysIUkDpuJwXAWI0dsIgehnBgSWSKUDyLhIOUAPxffCQ2Hwvy4JKSD4gdDC6waBAADxk+GoOnKLFqtWsciawAA4szyphoJztNAAArpCqNTDAABiWK4WoAEvgNFpdVbLWDtbl9bIFFqAKKSdDiXjQCaRG7WPmNaSKZVwcqgOK+4S8K5B4R3R5AlR8wiST4gWN+5nSbSBirJ6zicii5DAXPx3CwAsB67JuvaYAHTAkQitkjxlj4aTQCoiYBAhrvL6-IEvB7ArE40AAIk9mmEnIUoBt0mk88YROE4IArIxqblaV8AEygGGlF5TmfYr7zgAquCQAGkO2kOtvQLvwWejzSWBfAAzJe143tOmL3guer4MI0hBN+v7ngBJ5AaAoFXpOjx3nOT4vhAIiYAgyZIW8e4oTggHgph4G3lBeHPkgACCSQkHIZHEpRx7TOhACMYHYZBs4PkxoAAMqECw2jsJxFGgP+VFoX+gk3jhDEPgAsvg5QkaAABCOijo0cngnxqG8eCAAsqkQbhD6GYWKJnqZ3HUSBl5AoCcLwioz41Mq2gFMyLAFqAci2sR4VNJIJDSHpJENHuii1BokSHHALS2poAAURY3F8ibFuwACUqYvJG0bGai4yNuw1jGZgvzabw1i1Ah4g5S1uANTqTQ5WVABUtVJvVjXWPFNC8CV-wANwjj81hMiyxBovZC4APJhQAUggCoTLJnlwkAA)

 5. [DRY the houses when re-stocking](https://www.typescriptlang.org/play?#code/PTAEHUFNQCwQwG7TqAzpALqA9gM1tgK7qo4B2oKqGATpJqAO4wCWAxjAFAigDmLSUkSxs4ZACYBPShJxtRqFtjJwANqull640nQC01bGwDWLMrwB0nbmAAqrUi1JjK8wjTgZodAA510ZBieShR4oBgw0DBEJDagAEaEWBGQdADkzqCq2Fhh4oQ+quyekOKgbNji0GawqZAANDJlcZJETGLJ2OV0JZThkj7QzOww5USqZb7+kIGgcWLS0cSQVnEAkljZ2MakRcbQKeQa4azmTKwc5fDmkKTxmIz0ZHFLJKBOJ96Y7hQIaoTQMIAA1o7GMAHkaLYehggU04odcCwaNRQD44B4ALaYVI4fBA-wYIzGIEWOZxADCLlahFAyz6vBmqXY-UG4S6mLg+z6QIAEjFIHCMANoHFhpd4JlFOZVMgaLxCNjZrhsDRPqA6BgfqA-qoAXMeMDQSZIdDIJ44WIyod0Vj2aACbciSYgQB+azCtkAMWR1H59IAvKAAN6cUCgcTYVUAOUV9xoAC5QABGADcYfCNDBpphAAoAJRJgBE8SjxiLoAAPqAi6IJJIi+nw4TibmWF5Mahi6XthXq7WrQ3CzrsCxxOmAL7pzie6AAZUgFQk-vQoCDofDkZjcdSSYATE3M9moXnh0WiTkYPEaMQYH2a5izBhUI2My2TG2O12axeItfb-eRaPoEL7Dggo7jpwU4eiKoD2Mi4grtA64ZluNCxpi8ZJgAzIexoQie5oYAWxZ1lIgFwD4hSQIBkZkEkL6Hu+xifpAnakYOFFUbKtHKAxRZgRBk7TrOoBekQNAREha4hqhUboTuiagAALHhWYmoRngkTWZENlWNaoD4ZbSIZY6pIxb5Oq27Zsd+A71oBhnGWgPhmSiAlJuBY7CTBbJzrQ9BYEGADaPoohgSGNAuS6IQKjTwTQsXLI04nuFJAoALrpkAA)

## Intermediate/Advanced Challenges

1. [Sort Trick or Treat loot](https://www.typescriptlang.org/play?#code/PTAEE0HsFcCdQNYEsAmBnUALAhgNwKaiz4AucAdvilpALaEDuSJmo2oDmkANoQEbYA5gCgQoAGbRu3UJHFZs0yA3z5yobpEgkANG3LUAnjADkBUCWwI1FzIRJJ6FyKFFhaVwuxT40AY1gkAAcHSHU5NmlZeRZ8WgAuYWESQyDCAGVybD8EACFsWAwAXlAAb1dQUCz6eNAAInSuWBJQAGEuPx5sEkJ8wrrhSuxaGHISWoAWQdA-bANDWpJYaHxhAF8klLTQAHFoWgFpYrKKquH8WrqdrXxDXf3D7jQBys7NWEvBYjU60AAfepBOBBXjPaazeaLZarDbJVKEACCQRBvlAJXK02qF3qSJRYNecxQCws0PWm3hbS0yFR6NOWMurSpSF8LxmhOJSxW0zSc2gJDQUK5sK2GXISBy+EKfTRJ0x50umXF1kKoD6rIhRMFq0qPPIfIFJKF5O2ABUtCwgtg0D0ZRj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FE7FRWsh1Lqml7KOT0kJFyRk3KmXMlErhikIZQ3UvEniDknHOUMqAYy6TZJUSoXRGyPMDAJKKckkpZSPKUQyV5aYPk-JBmiSSYK1p8oewQR7ZAaRdTGhwDeO8gyvagA1ByIqa8s4UFig4-BFAACyoNErAQhhQrh8ALEziYQuYWZ0mC2B2OLIwazNm0wWrEsm8Beo7VmjlG5WzMa1OeTrV5pyYDnNQPaZZ7y7mjQed1J5As2aCxBZzOmOSGaTWZlCgWg1YWIC5ktPmoJUVrQNmAEWYs7qYPhKgxAOtR7WjNhAbUxdQBIEgRqUAv94BEEQDdHmxBg5VGsHocBipz7YF-icHIthCBNw7MhbOmAs6tEpdaROoA2LsHoK6S09K2qUFFtgR0LL7GqrznymUjxyidgMIKy0lUkCNFnpAJIvgTSoEgJYPOyzTCUVKNYTUtLxlMvdKQOVlLTAAGY-TLw7HUFQ0qkgOVrHUNA9ADVlQLkwexjw0DsGUeWPVvgpW2BlROFYnd1VRhjKHFQRggA)

## Yesterday's Solution
### Beginner/Learner Challenge

Like many challenges, you answer to this depends on how thorough you wanted to type the houses. 
The in-challenge text tries to guide you to answer with a single generic type which passes the first argument to both `trickOrTreat` and `restock`.

```ts
type House<Candy> = {
  doorNumber: number
  trickOrTreat(): Candy;
  restock(items: Candy): void;
}

type FirstHouse = House<"book" | "candy">

type SecondHouse = House<"toothbrush" | "mints">

// ... same pattern for the rest
```

This could be enough, and that's totally enough type safety for cases like this. This does lose the `doorNumber` being exact though. So, here are two different routes to give the `doorNumber` to each house:

```ts
// Via a 2nd generic argument
type House<DoorNumber, Candy> = {
  doorNumber: DoorNumber
  trickOrTreat(): Candy;
  restock(items: Candy): void;
}

type FirstHouse = House<1, "book" | "candy">

type SecondHouse = House<2, "toothbrush" | "mints">

// ... same pattern for the rest
```

and

```ts
type House<Candy> = {
  doorNumber: number
  trickOrTreat(): Candy;
  restock(items: Candy): void;
}

// Via intersection types:
type FirstHouse = House<"book" | "candy"> & { doorNumber: 1 }

type SecondHouse = House<"toothbrush" | "mints"> & { doorNumber: 2 }
```

[Our answer](https://www.typescriptlang.org/play?#code/PTAEHUFNQCwQwG7TqAzpALqA9gM1tgK7qo4B2oKqGATpJqAO4wCWAxjAFAigDmLSUkSxs4ZACYBPShJxtRqFtjJwANqull640nQC01bGwDWLMrwB0nbmAAqrUi1JjK8wjTgZodAA510ZBieShR4oBgw0DBEJDagAEaEWBGQdADkzqCq2Fhh4oQ+quyekOKgbNji0GawqZAANDJlcZJETGLJ2OV0JZThkj7QzOww5USqZb7+kIGgcWLS0cSQVnEAkljZ2MakRcbQKeQa4azmTKwc5fDmkKTxmIz0ZHFLJKBOJ96Y7hQIaoTQMIAA1o7GMAHkaLYehggU04odcCwaNRQD44B4ALaYVI4fBA-wYIzGIEWOZxADCLlahFAyz6vBmqXY-UG4S6mLg+z6QIAEjFIHCMANoHFhpd4JlFOZVMgaLxCNjZrhsDRPqA6BgfqA-qoAXMeMDQSZIdDIJ44WIyod0Vj2aACbciSYgQB+azCtn85YAHgAIthVQA5RX3GiNKkSSQAPlAAF5QABvTigUDiQM0EOYsMALlAAeDodSKfCNDBpphAAoAJR5yNSADcJcJxMrLC8mNQdatklrOuwLHETYAvh6RaAAGLI6je9Dx0CzyA+gCMjQARPFA8Y16AAD6gNeiKNr6NjtkAZUgFQki-ni59ACZ10ScjB4jRiDAd-u15izBhUBPM9oHsZFxFvBN7wAZnXI8pG-A84B8QpIAQtd0zIJJANPThPWgCciBoCIIIXAUfQAFlgns0NQHwt2kWjB1SbDgNAc9aHoLAEwAbSnFEMEXRpL2vcCBUaUCaFE5ZGgI9xiIFABdJsgA).

### Intermediate/Advanced Challenge  

OK, this one is tricky. It's based on [this Playground example](https://www.typescriptlang.org/play?ts=4.1.0-dev.20201028&q=248#example/mapped-types-with-template-literals). 

We started out by making types for passing the data around

```ts
type Movies = typeof moviesToShow
type Movie = { forKids: boolean }

// Template strings literals to describe each task
type Get<T extends string> = `getVHSFor${capitalize T}`
type MakePopcorn<T extends string> = `makePopcornFor${capitalize T}`
type Play<T extends string> = `play${capitalize T }`

// A union of the above literal types
type Tasks<T extends string> = Get<T> | MakePopcorn<T> | Play<T>
```

These gave us a set of primitives which could work together to create this whopper:

```ts
type MakeScheduler<Type> = {
  [Field in keyof Type as Tasks<Field extends string ? Field : never>]: () => void;
};
```

This type uses the new `as` syntax for mapped types in TypeScript 4.1 to essentially map each field (Field) from the keys in the input type (Type) to the union `Tasks` above. This means that each field is converted into three templated literals: 

```sh
input: `"halloween"` turns to:
  ├─ Get<"halloween"> -> `getVHSForHalloween`
  ├─ MakePopcorn<"halloween"> -> `makePopcornForHalloween`
  └─ Play<"halloween"> -> `playHalloween`
```
Which is declared to be a function which returns void.

This type is then used as the return type for the `makeScheduler` function:

```ts
function makeScheduler(movies: Movies): MakeScheduler<Movies> {
```

For simplicities sake, we skipped typing the inside of the function - though the folks who did that, good work!

The second part added one simple constraint, but one that requires some work to get right. We wanted to take into account whether a movie was for kids of not _inside the type system_.

Our answer for this was to recreate the scheduler function above, and to add the logic for removing those types during the type mapping process.

```ts
type MakeKidsScheduler<Type> = {
  [Field in keyof Type as Tasks<Field extends string ? Field : never>]:
    Type[Field] extends { forKids: true } ?  () => void : never;
};
```

Instead of returning a `() => void`, we inserted a conditional type in the return position which first checked if `forKids` is `true` in the original type. If it was, then it returned the function - otherwise it returned `never`. Returning never here would mean that the function would not exist - removing them from the mapping process.

The community came up with quite a few alternative takes which provided type safety inside the functions and used different routes like [removing the non-kids movie](https://twitter.com/danvdk/status/1322546300617969664) [keys ahead of time](https://twitter.com/RickLoveToldMe/status/1322321114132086784). 

[Our answer](https://www.typescriptlang.org/play?ts=4.1.0-beta#code/PTAEE0HsFcHICcCmoAOBDeAXUkBmo1RNE0BbUAZwGMALRAE2gBsBLAOwHMDRTIA3FsjYsONTABpQAI2jYKkUokhtkaKlRb1EbTGiZMAngCgQoKsoqbESekTo9+g0ACIAKvYByIsaQzIAQoi4kEigAMI08CwUmL4UzkSQ0qqgNHpMkAD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M2hqwtdbMWTcJb4X1tLJgRsDQKydqK82dbQ4ki1rFHWgCW3pvbQ7TtJsFq9rVv2kWulUp20xhOrtIrp3jFVnW5krt5HTA9l7IMc72QxW1ZsFV919V9kPMnYcCF-bWgzhYr5FjkBpF1MaHArrtpPqsVZPYHJs5DJ7J5c1kKKCPRvrHU99Bz0J0NTe1ObDd4dR2CfIwYGIOTzvs2-B7d5hdwwz-eu088OdwwaYFO1y4yeUI6Q3+2G8EEOoSwtOtH6G-3IbrShhCWPoc2Jh+BqUmPMOIRguRFGOEn2sGYZRnYZFZEadaNREBtTxNAEgZ5GpQAXPgEQC8V4bwuWfGEhMbzsAXJODkWwhA8k8EMi2Wwq5WiKetP46lxZKUOSiDHCgHDsCOh069egVQFVuRlHeKg24DBLM6XQQuSBGidIXHZk0qBICWDzp5UwKNSjWE1Kpj9Wn3SkGc4p0wABmP0-S7N1BUOEimNzax1DQPQYLec3IdEeGgdggbyyBd8DTergESkKEtCsaMpiVBGCAA)

## Share Your Experience

We would love to hear your feedback on this weeks challenges whether good or a bad! If you can please take our quick 4 question survey that can be found [here](https://www.surveymonkey.com/r/FSQ7DLC)

## Want More?!

If you want to learn more about TypeScript, check out some of our best resources:

- [The TypeScript Handbook](https://www.typescriptlang.org/docs/handbook/intro.html)
- [The TypeScript Playground](https://www.typescriptlang.org/play?target=1&q=326#example/hello-world)
- [The TypeScript Blog](https://devblogs.microsoft.com/typescript/)

Happy Typing :)