From 6e8bbabf32664a46d5f1438c5667008b51158a1c Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Sun, 1 Sep 2024 18:10:19 +0800 Subject: [PATCH] Option works! Yay: https://stackoverflow.com/a/59840928 --- commitlint/tests/integration.test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/commitlint/tests/integration.test.ts b/commitlint/tests/integration.test.ts index 7e8d3bdd..4ec99d76 100644 --- a/commitlint/tests/integration.test.ts +++ b/commitlint/tests/integration.test.ts @@ -50,6 +50,16 @@ function fn(p: C) { } } +class None {} +class Value { + value: T; + + constructor(val: T) { + this.value = val; + } +} +type Option = None | Value; + test("testing DUs", () => { let foo = new A(); expect(foo.x).toBe("hello"); @@ -63,3 +73,19 @@ test("testing DUs", () => { let bar2 = fn(bar); expect(bar2).toBe("1"); }); + +function fnO(option: Option) { + if (option instanceof None) { + return "NAH"; + } else { + let val = option.value; + return (val * val).toString(); + } +} + +test("testing Options", () => { + let foo: Option = new None(); + let bar: Option = new Value(2); + expect(fnO(foo)).toBe("NAH"); + expect(fnO(bar)).toBe("4"); +});