|
| 1 | +import { Expect, Equal } from "../test"; |
| 2 | + |
| 3 | +/** |
| 4 | + * **💋Crystal Panics** |
| 5 | + * |
| 6 | + * [💋Crystal Claus, 🎅Santa's wife, has been unhappy in her marriage. 🎅Santa goes on days-long benders where he's almost impossible to tolerate. 💋Crystal has needs too, after all. 🪩Jamie Glitterglum, 💋Crystal's long time friend, has recently made some... advances, and 💋Crystal isn't sure what to do. 💋Crystal confides in 🎩Bernard.] |
| 7 | + * |
| 8 | + * [💋Crystal] He's gonna kill me, 🎩Bernard. Or worse, he’ll leave me stranded at the North Pole with no Wi-Fi and zero prospects. |
| 9 | + * |
| 10 | + * [🎩Bernard] Did anything actually happen though? |
| 11 | + * |
| 12 | + * [💋Crystal] Well not exactly......... |
| 13 | + * |
| 14 | + * [🎩Bernard, looking skeptical] ?? |
| 15 | + * |
| 16 | + * [💋Crystal] It’s complicated!! Things just kinda... escalated over mulled wine and snowman-shaped Jello shots! |
| 17 | + * |
| 18 | + * [🎩Bernard] How exactly does one sorta have an affair behind the back of the Patron of Yuletide, himself? Did you trip and fall into 🪩Jamie's lap or something? |
| 19 | + * |
| 20 | + * [💋Crystal] 🪩Jamie and I haven't quite exactly... well... it's complicated!! |
| 21 | + * |
| 22 | + * [🎩Bernard] You better make it less complicated! and soon! Although, thankfully it's 🎅Santa we're talkin' about. The guy thinks JSON is a new kind of cookie. |
| 23 | + * |
| 24 | + * [💋Crystal] I know exactly what to do. 🎅Santa's been super frustrated with the work of those damn reindeer. They've been developing this subroutine to create new routes on Christmas night, but it's not working correctly. The literal values won't infer like they're supposed to. It's close but.... I think if I can fix it, I can keep 🎅Santa from going on another rage-filled tirade. I gotta keep him content. |
| 25 | + * |
| 26 | + * [🎩Bernard] Then this would mark the first time I’ve seen him not rage-punch a snow globe over the slightest inconvenience. |
| 27 | + * |
| 28 | + * Hint |
| 29 | + * |
| 30 | + * How can you get TypeScript to automatically infer a more narrow type? |
| 31 | + */ |
| 32 | +const createRoute = <const Route extends string[]>(author: string, route: Route) => ({ |
| 33 | + author, |
| 34 | + route, |
| 35 | + createdAt: Date.now(), |
| 36 | +}); |
| 37 | + |
| 38 | +// ************************************************************************************* |
| 39 | +// *** Tests *** |
| 40 | +// ************************************************************************************* |
| 41 | + |
| 42 | +const oneMill = createRoute("💨Dasher", ["Atherton", "Scarsdale", "Cherry Hills Village"]).route; |
| 43 | +type t0_actual = typeof oneMill; // => |
| 44 | +type t0_expected = [ |
| 45 | + // => |
| 46 | + "Atherton", |
| 47 | + "Scarsdale", |
| 48 | + "Cherry Hills Village" |
| 49 | +]; |
| 50 | +type t0 = Expect<Equal<t0_actual, t0_expected>>; |
| 51 | + |
| 52 | +const two = createRoute("🌟Vixen", ["Detroit", "Cleveland", "Dayton"]).route; |
| 53 | +type t1_actual = typeof two; // => |
| 54 | +type t1_expected = [ |
| 55 | + // => |
| 56 | + "Detroit", |
| 57 | + "Cleveland", |
| 58 | + "Dayton" |
| 59 | +]; |
| 60 | +type t1 = Expect<Equal<t1_actual, t1_expected>>; |
0 commit comments