diff --git a/lib/core.ts b/lib/core.ts index 172a63117..32666bd44 100644 --- a/lib/core.ts +++ b/lib/core.ts @@ -298,10 +298,10 @@ export default class Ajv { // AnySchema will be compiled and cached using schema itself as a key for Map validate(schema: Schema | string, data: unknown): boolean validate(schemaKeyRef: AnySchema | string, data: unknown): boolean | Promise - validate( - schema: Schema | JTDSchemaType | JSONSchemaType | string, - data: unknown - ): data is T + validate(schema: Schema | JSONSchemaType | string, data: unknown): data is T + // This is separated to help typescript with inference + // eslint-disable-next-line @typescript-eslint/unified-signatures + validate(schema: JTDSchemaType, data: unknown): data is T validate(schema: AsyncSchema, data: unknown | T): Promise validate(schemaKeyRef: AnySchema | string, data: unknown): data is T | Promise validate( @@ -323,10 +323,10 @@ export default class Ajv { // Create validation function for passed schema // _meta: true if schema is a meta-schema. Used internally to compile meta schemas of user-defined keywords. - compile( - schema: Schema | JTDSchemaType | JSONSchemaType, - _meta?: boolean - ): ValidateFunction + compile(schema: Schema | JSONSchemaType, _meta?: boolean): ValidateFunction + // This is separated to help typescript with inference + // eslint-disable-next-line @typescript-eslint/unified-signatures + compile(schema: JTDSchemaType, _meta?: boolean): ValidateFunction compile(schema: AsyncSchema, _meta?: boolean): AsyncValidateFunction compile(schema: AnySchema, _meta?: boolean): AnyValidateFunction compile(schema: AnySchema, _meta?: boolean): AnyValidateFunction { diff --git a/package.json b/package.json index 6a719ca9e..13f1c6887 100644 --- a/package.json +++ b/package.json @@ -99,7 +99,7 @@ "terser": "^5.2.1", "ts-node": "^9.0.0", "tsify": "^5.0.2", - "typescript": "^4.0.0", + "typescript": "^4.2.0", "vuepress": "^1.8.2" }, "collective": { diff --git a/spec/types/jtd-schema.spec.ts b/spec/types/jtd-schema.spec.ts index 2b95630fa..da88e8982 100644 --- a/spec/types/jtd-schema.spec.ts +++ b/spec/types/jtd-schema.spec.ts @@ -30,14 +30,14 @@ const mySchema: JTDSchemaType = { describe("JTDSchemaType", () => { it("validation should prove the data type", () => { const ajv = new _Ajv() - const validate = ajv.compile(mySchema) + const validate = ajv.compile(mySchema) const validData: unknown = {type: "a", a: 1} if (validate(validData) && validData.type === "a") { validData.a.should.equal(1) } should.not.exist(validate.errors) - if (ajv.validate(mySchema, validData) && validData.type === "a") { + if (ajv.validate(mySchema, validData) && validData.type === "a") { validData.a.should.equal(1) } should.not.exist(ajv.errors)