From 823fbd42b5cc74165beb08f8c40aaaf6507f3de2 Mon Sep 17 00:00:00 2001 From: Massimiliano Sartoretto Date: Tue, 4 May 2021 11:29:26 +0000 Subject: [PATCH] Add boolean support to JTDDataType --- lib/types/jtd-schema.ts | 2 ++ spec/types/jtd-schema.spec.ts | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/lib/types/jtd-schema.ts b/lib/types/jtd-schema.ts index 0c76741b5..c5d70ef8b 100644 --- a/lib/types/jtd-schema.ts +++ b/lib/types/jtd-schema.ts @@ -206,6 +206,8 @@ type JTDDataDef> = : // type S extends {type: NumberType} ? number + : S extends {type: "boolean"} + ? boolean : S extends {type: "string"} ? string : S extends {type: "timestamp"} diff --git a/spec/types/jtd-schema.spec.ts b/spec/types/jtd-schema.spec.ts index e9c3d5d0f..eafb822e1 100644 --- a/spec/types/jtd-schema.spec.ts +++ b/spec/types/jtd-schema.spec.ts @@ -373,6 +373,13 @@ describe("JTDDataType", () => { void [num] }) + it("should typecheck boolean schemas", () => { + const booleanSchema = {type: "boolean"} as const + const bool: TypeEquality, boolean> = true + + void [bool] + }) + it("should typecheck string schemas", () => { const strSchema = {type: "string"} as const const str: TypeEquality, string> = true