From 067d5043b58666a33c0f397af1990988d1f239e7 Mon Sep 17 00:00:00 2001 From: Mark Heimer Date: Thu, 2 Feb 2023 10:31:05 +0100 Subject: [PATCH] feat/solution-17: implement solution without type casts --- ...-you-say-goodbye-i-say-hello.solution.3.ts | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/04-generics-advanced/17-you-say-goodbye-i-say-hello.solution.3.ts diff --git a/src/04-generics-advanced/17-you-say-goodbye-i-say-hello.solution.3.ts b/src/04-generics-advanced/17-you-say-goodbye-i-say-hello.solution.3.ts new file mode 100644 index 0000000..8a4f181 --- /dev/null +++ b/src/04-generics-advanced/17-you-say-goodbye-i-say-hello.solution.3.ts @@ -0,0 +1,26 @@ +import { expect, it } from "vitest"; +import { Equal, Expect } from "../helpers/type-utils"; + +function youSayGoodbyeISayHello(greeting: 'hello'): 'goodbye' +function youSayGoodbyeISayHello(greeting: 'goodbye'): 'hello' +function youSayGoodbyeISayHello( + greeting: TGreeting +){ + return greeting === "goodbye" ? "hello" : "goodbye"; +} + +it("Should return goodbye when hello is passed in", () => { + const result = youSayGoodbyeISayHello("hello"); + + type test = [Expect>]; + + expect(result).toEqual("goodbye"); +}); + +it("Should return hello when goodbye is passed in", () => { + const result = youSayGoodbyeISayHello("goodbye"); + + type test = [Expect>]; + + expect(result).toEqual("hello"); +});