From 8539e5e4254303fb28c9ca513da0b0d876edc4bb Mon Sep 17 00:00:00 2001 From: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> Date: Sun, 12 Sep 2021 10:13:31 +0100 Subject: [PATCH] update code for breaking typescript change (catched error now has type `unknown`, not `any` as before) --- lib/runtime/parseJson.ts | 2 +- lib/types/jtd-schema.ts | 28 ++++++++++++---------------- spec/ajv.spec.ts | 2 +- spec/resolve.spec.ts | 6 ++++-- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/runtime/parseJson.ts b/lib/runtime/parseJson.ts index 6b0845990..92579afeb 100644 --- a/lib/runtime/parseJson.ts +++ b/lib/runtime/parseJson.ts @@ -9,7 +9,7 @@ export function parseJson(s: string, pos: number): unknown { parseJson.position = pos + s.length return JSON.parse(s) } catch (e) { - matches = rxParseJson.exec(e.message) + matches = rxParseJson.exec((e as Error).message) if (!matches) { parseJson.message = "unexpected end" return undefined diff --git a/lib/types/jtd-schema.ts b/lib/types/jtd-schema.ts index c5d70ef8b..e1eaf0fb2 100644 --- a/lib/types/jtd-schema.ts +++ b/lib/types/jtd-schema.ts @@ -228,27 +228,23 @@ type JTDDataDef> = optionalProperties?: Record additionalProperties?: boolean } - ? {-readonly [K in keyof S["properties"]]-?: JTDDataDef} & - { - -readonly [K in keyof S["optionalProperties"]]+?: JTDDataDef< - S["optionalProperties"][K], - D - > - } & - ([S["additionalProperties"]] extends [true] ? Record : unknown) + ? {-readonly [K in keyof S["properties"]]-?: JTDDataDef} & { + -readonly [K in keyof S["optionalProperties"]]+?: JTDDataDef< + S["optionalProperties"][K], + D + > + } & ([S["additionalProperties"]] extends [true] ? Record : unknown) : S extends { properties?: Record optionalProperties: Record additionalProperties?: boolean } - ? {-readonly [K in keyof S["properties"]]-?: JTDDataDef} & - { - -readonly [K in keyof S["optionalProperties"]]+?: JTDDataDef< - S["optionalProperties"][K], - D - > - } & - ([S["additionalProperties"]] extends [true] ? Record : unknown) + ? {-readonly [K in keyof S["properties"]]-?: JTDDataDef} & { + -readonly [K in keyof S["optionalProperties"]]+?: JTDDataDef< + S["optionalProperties"][K], + D + > + } & ([S["additionalProperties"]] extends [true] ? Record : unknown) : // values S extends {values: infer V} ? Record> diff --git a/spec/ajv.spec.ts b/spec/ajv.spec.ts index 5b65b140c..31497935f 100644 --- a/spec/ajv.spec.ts +++ b/spec/ajv.spec.ts @@ -225,7 +225,7 @@ describe("Ajv", () => { ajv.addSchema({$id: 1, type: "integer"}) throw new Error("should have throw exception") } catch (e) { - e.message.should.equal("schema $id must be string") + ;(e as Error).message.should.equal("schema $id must be string") } }) diff --git a/spec/resolve.spec.ts b/spec/resolve.spec.ts index 2edaea39e..db1663ccb 100644 --- a/spec/resolve.spec.ts +++ b/spec/resolve.spec.ts @@ -1,7 +1,8 @@ import type AjvCore from "../dist/core" import getAjvInstances from "./ajv_instances" import _Ajv from "./ajv" -import {AnyValidateFunction} from "../dist/types" +import type {AnyValidateFunction} from "../dist/types" +import type MissingRefError from "../dist/compile/ref_error" import chai from "./chai" const should = chai.should() @@ -200,7 +201,8 @@ describe("resolve", () => { type: "object", properties: {a: {$ref: opts.ref}}, }) - } catch (e) { + } catch (err) { + const e = err as MissingRefError e.missingRef.should.equal(opts.expectedMissingRef) e.missingSchema.should.equal(opts.expectedMissingSchema) }