diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..0cc3db4 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,13 @@ +import { Ajv, Options } from "ajv"; + +export type ValidatorCompiler = ( + externalSchemas: unknown, + options: Options, + cache: Options["cache"] +) => Ajv; + +export declare function ValidatorSelector(): ValidatorCompiler; + +export type { Ajv, Options } from "ajv"; + +export default ValidatorSelector; diff --git a/package.json b/package.json index e094d9a..ef87dd1 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,15 @@ "version": "1.0.0", "description": "Build and manage the AJV instances for the fastify framework", "main": "index.js", + "types": "index.d.ts", "directories": { "test": "test" }, "scripts": { "lint:fix": "standard --fix", - "test": "standard && tap --100 test/**/*.test.js" + "unit": "tap --100 test/**/*.test.js", + "test": "standard && npm run unit && npm run test:typescript", + "test:typescript": "tsd" }, "repository": { "type": "git", @@ -31,9 +34,13 @@ "ajv-errors": "^1.0.1", "ajv-merge-patch": "^4.1.0", "standard": "^16.0.3", - "tap": "^15.0.1" + "tap": "^15.0.1", + "tsd": "^0.14.0" }, "dependencies": { "ajv": "^6.12.6" + }, + "tsd": { + "directory": "test/types" } } diff --git a/test/types/index.test.ts b/test/types/index.test.ts new file mode 100644 index 0000000..5cd42f0 --- /dev/null +++ b/test/types/index.test.ts @@ -0,0 +1,6 @@ +import { expectType } from "tsd"; +import ValidatorSelector, { ValidatorCompiler } from "../.."; + +const compiler = ValidatorSelector(); + +expectType(compiler);