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 e8071d67f..f70790479 100644 --- a/package.json +++ b/package.json @@ -96,7 +96,7 @@ "terser": "^5.2.1", "ts-node": "^9.0.0", "tsify": "^5.0.2", - "typescript": "^4.0.0" + "typescript": "^4.2.0" }, "collective": { "type": "opencollective", diff --git a/spec/types/jtd-schema.spec.ts b/spec/types/jtd-schema.spec.ts index a6f3c3dc3..60e3c1662 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)