Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update code for breaking typescript change (catched error now has type unknown, not any as before) #1760

Merged
merged 1 commit into from
Sep 12, 2021
Merged
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
2 changes: 1 addition & 1 deletion lib/runtime/parseJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 12 additions & 16 deletions lib/types/jtd-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,27 +228,23 @@ type JTDDataDef<S, D extends Record<string, unknown>> =
optionalProperties?: Record<string, unknown>
additionalProperties?: boolean
}
? {-readonly [K in keyof S["properties"]]-?: JTDDataDef<S["properties"][K], D>} &
{
-readonly [K in keyof S["optionalProperties"]]+?: JTDDataDef<
S["optionalProperties"][K],
D
>
} &
([S["additionalProperties"]] extends [true] ? Record<string, unknown> : unknown)
? {-readonly [K in keyof S["properties"]]-?: JTDDataDef<S["properties"][K], D>} & {
-readonly [K in keyof S["optionalProperties"]]+?: JTDDataDef<
S["optionalProperties"][K],
D
>
} & ([S["additionalProperties"]] extends [true] ? Record<string, unknown> : unknown)
: S extends {
properties?: Record<string, unknown>
optionalProperties: Record<string, unknown>
additionalProperties?: boolean
}
? {-readonly [K in keyof S["properties"]]-?: JTDDataDef<S["properties"][K], D>} &
{
-readonly [K in keyof S["optionalProperties"]]+?: JTDDataDef<
S["optionalProperties"][K],
D
>
} &
([S["additionalProperties"]] extends [true] ? Record<string, unknown> : unknown)
? {-readonly [K in keyof S["properties"]]-?: JTDDataDef<S["properties"][K], D>} & {
-readonly [K in keyof S["optionalProperties"]]+?: JTDDataDef<
S["optionalProperties"][K],
D
>
} & ([S["additionalProperties"]] extends [true] ? Record<string, unknown> : unknown)
: // values
S extends {values: infer V}
? Record<string, JTDDataDef<V, D>>
Expand Down
2 changes: 1 addition & 1 deletion spec/ajv.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
})

Expand Down
6 changes: 4 additions & 2 deletions spec/resolve.spec.ts
Original file line number Diff line number Diff line change
@@ -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()

Expand Down Expand Up @@ -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)
}
Expand Down