Skip to content

Commit

Permalink
add tests to verify improper enum
Browse files Browse the repository at this point in the history
New tests verify that incorrect types on an enum trigger a never type
  • Loading branch information
erikbrinkman committed Feb 22, 2021
1 parent 176fc47 commit 9c10999
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion spec/types/jtd-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,14 @@ describe("JTDDataType typechecks", () => {
const enumSchema = {enum: ["a", "b"]} as const
const enumerated: TypeEquality<JTDDataType<typeof enumSchema>, "a" | "b"> = true

void [enumerated]
// if you forget const on an enum it will error
const enumStringSchema = {enum: ["a", "b"]}
const enumString: TypeEquality<JTDDataType<typeof enumStringSchema>, never> = true
// also if not a string
const enumNumSchema = {enum: [3]} as const
const enumNum: TypeEquality<JTDDataType<typeof enumNumSchema>, never> = true

void [enumerated, enumString, enumNum]
})

it("should typecheck elements schemas", () => {
Expand Down

0 comments on commit 9c10999

Please sign in to comment.