From 9c109995b380b6d531393dac430ba240662a88d4 Mon Sep 17 00:00:00 2001 From: Erik Brinkman Date: Mon, 22 Feb 2021 13:44:35 -0500 Subject: [PATCH] add tests to verify improper enum New tests verify that incorrect types on an enum trigger a never type --- spec/types/jtd-schema.spec.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/spec/types/jtd-schema.spec.ts b/spec/types/jtd-schema.spec.ts index d8c4425ac..d3061818e 100644 --- a/spec/types/jtd-schema.spec.ts +++ b/spec/types/jtd-schema.spec.ts @@ -350,7 +350,14 @@ describe("JTDDataType typechecks", () => { const enumSchema = {enum: ["a", "b"]} as const const enumerated: TypeEquality, "a" | "b"> = true - void [enumerated] + // if you forget const on an enum it will error + const enumStringSchema = {enum: ["a", "b"]} + const enumString: TypeEquality, never> = true + // also if not a string + const enumNumSchema = {enum: [3]} as const + const enumNum: TypeEquality, never> = true + + void [enumerated, enumString, enumNum] }) it("should typecheck elements schemas", () => {