Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/types/jtd-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ export type JTDSchemaType<T, D extends Record<string, unknown> = Record<string,
: // enums - only accepts union of string literals
// TODO we can't actually check that everything in the union was specified
true extends IsEnum<Exclude<T, null>>
? {enum: EnumString<Exclude<T, null>>[]}
? // eslint-disable-next-line @typescript-eslint/array-type
{enum: ReadonlyArray<EnumString<Exclude<T, null>>>}
: // arrays - only accepts arrays, could be array of unions to be resolved later
true extends IsElements<Exclude<T, null>>
? T extends readonly (infer E)[]
Expand Down
12 changes: 11 additions & 1 deletion spec/types/jtd-schema.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,17 @@ describe("JTDSchemaType", () => {
const enumerateString: JTDSchemaType<"a" | "b"> = {type: "string"}
const enumerateNull: JTDSchemaType<"a" | "b" | null> = {enum: ["a", "b"], nullable: true}

void [enumerate, enumerateMissing, enumerateNumber, enumerateString, enumerateNull]
const constEnumSchema = {enum: ["a", "b"]} as const
const enumerateConst: JTDSchemaType<"a" | "b"> = constEnumSchema

void [
enumerate,
enumerateMissing,
enumerateNumber,
enumerateString,
enumerateNull,
enumerateConst,
]
})

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