diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 386ab5907..0babade7a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -75,6 +75,16 @@ jobs: run: | npm run test:types + - name: Test types (object-schema) + working-directory: packages/object-schema + run: | + npm run test:types + + - name: Test types (config-array) + working-directory: packages/config-array + run: | + npm run test:types + - name: Test types (config-helpers) working-directory: packages/config-helpers run: | diff --git a/packages/config-array/package.json b/packages/config-array/package.json index c5203223f..26347befc 100644 --- a/packages/config-array/package.json +++ b/packages/config-array/package.json @@ -36,10 +36,11 @@ "build:cts": "node ../../tools/build-cts.js dist/esm/index.d.ts dist/cjs/index.d.cts", "build:std__path": "rollup -c rollup.std__path-config.js && node fix-std__path-imports", "build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts && npm run build:std__path", - "test:jsr": "npx jsr@latest publish --dry-run", "pretest": "npm run build", "test": "mocha \"tests/**/*.test.js\"", - "test:coverage": "c8 npm test" + "test:coverage": "c8 npm test", + "test:jsr": "npx jsr@latest publish --dry-run", + "test:types": "tsc -p tests/types/tsconfig.json" }, "keywords": [ "configuration", diff --git a/packages/config-array/rollup.config.js b/packages/config-array/rollup.config.js index 03a11e126..5b813a884 100644 --- a/packages/config-array/rollup.config.js +++ b/packages/config-array/rollup.config.js @@ -16,7 +16,7 @@ export default { plugins: [ copy({ targets: [ - { src: "src/types.ts", dest: "dist/cjs" }, + { src: "src/types.ts", dest: "dist/cjs", rename: "types.cts" }, { src: "src/types.ts", dest: "dist/esm" }, ], }), diff --git a/packages/config-array/rollup.std__path-config.js b/packages/config-array/rollup.std__path-config.js index 2a9317ec7..44912051b 100644 --- a/packages/config-array/rollup.std__path-config.js +++ b/packages/config-array/rollup.std__path-config.js @@ -7,10 +7,12 @@ export default [ input: resolve("@jsr/std__path/posix"), output: [ { + banner: "// @ts-nocheck", file: "./dist/cjs/std__path/posix.cjs", format: "cjs", }, { + banner: "// @ts-nocheck", file: "./dist/esm/std__path/posix.js", format: "esm", }, @@ -20,10 +22,12 @@ export default [ input: resolve("@jsr/std__path/windows"), output: [ { + banner: "// @ts-nocheck", file: "./dist/cjs/std__path/windows.cjs", format: "cjs", }, { + banner: "// @ts-nocheck", file: "./dist/esm/std__path/windows.js", format: "esm", }, diff --git a/packages/config-array/src/config-array.js b/packages/config-array/src/config-array.js index 075cef701..cbd373ba8 100644 --- a/packages/config-array/src/config-array.js +++ b/packages/config-array/src/config-array.js @@ -20,12 +20,10 @@ import { filesAndIgnoresSchema } from "./files-and-ignores-schema.js"; // Types //------------------------------------------------------------------------------ -/** @typedef {import("@eslint/object-schema").PropertyDefinition} PropertyDefinition */ -/** @typedef {import("@eslint/object-schema").ObjectDefinition} ObjectDefinition */ /** @typedef {import("./types.ts").ConfigObject} ConfigObject */ /** @typedef {import("minimatch").IMinimatchStatic} IMinimatchStatic */ /** @typedef {import("minimatch").IMinimatch} IMinimatch */ -/** @typedef {import("@jsr/std__path")} PathImpl */ +/** @import * as PathImpl from "@jsr/std__path" */ /* * This is a bit of a hack to make TypeScript happy with the Rollup-created @@ -34,7 +32,7 @@ import { filesAndIgnoresSchema } from "./files-and-ignores-schema.js"; * for `ObjectSchema`. To work around that, we just import the type manually * and give it a different name to use in the JSDoc comments. */ -/** @typedef {import("@eslint/object-schema").ObjectSchema} ObjectSchemaInstance */ +/** @typedef {ObjectSchema} ObjectSchemaInstance */ //------------------------------------------------------------------------------ // Helpers @@ -968,7 +966,8 @@ export class ConfigArray extends Array { * @param {Object} config The config to finalize. * @returns {Object} The finalized config. */ - [ConfigArraySymbol.finalizeConfig](config) { + // Cast key to `never` to prevent TypeScript from adding the signature `[x: symbol]: (config: any) => any` to the type of the class. + [/** @type {never} */ (ConfigArraySymbol.finalizeConfig)](config) { return config; } @@ -980,7 +979,8 @@ export class ConfigArray extends Array { * @param {Object} config The config to preprocess. * @returns {Object} The config to use in place of the argument. */ - [ConfigArraySymbol.preprocessConfig](config) { + // Cast key to `never` to prevent TypeScript from adding the signature `[x: symbol]: (config: any) => any` to the type of the class. + [/** @type {never} */ (ConfigArraySymbol.preprocessConfig)](config) { return config; } diff --git a/packages/config-array/tests/types/cjs-import.test.cts b/packages/config-array/tests/types/cjs-import.test.cts new file mode 100644 index 000000000..f80a15616 --- /dev/null +++ b/packages/config-array/tests/types/cjs-import.test.cts @@ -0,0 +1,10 @@ +/** + * @fileoverview CommonJS type import test for Config Array package. + * @author Francesco Trotta + */ + +//----------------------------------------------------------------------------- +// Imports +//----------------------------------------------------------------------------- + +import "@eslint/config-array"; diff --git a/packages/config-array/tests/types/tsconfig.json b/packages/config-array/tests/types/tsconfig.json new file mode 100644 index 000000000..638c0f3a5 --- /dev/null +++ b/packages/config-array/tests/types/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "noEmit": true, + "rootDir": "../.." + }, + "include": [".", "../../dist"] +} diff --git a/packages/config-array/tests/types/types.test.ts b/packages/config-array/tests/types/types.test.ts new file mode 100644 index 000000000..7b9ff36d2 --- /dev/null +++ b/packages/config-array/tests/types/types.test.ts @@ -0,0 +1,10 @@ +/** + * @fileoverview Type tests for Config Array package. + * @author Francesco Trotta + */ + +//----------------------------------------------------------------------------- +// Imports +//----------------------------------------------------------------------------- + +import "@eslint/config-array"; diff --git a/packages/object-schema/package.json b/packages/object-schema/package.json index f016d77b3..dbb23e1ce 100644 --- a/packages/object-schema/package.json +++ b/packages/object-schema/package.json @@ -27,9 +27,10 @@ "scripts": { "build:cts": "node ../../tools/build-cts.js dist/esm/index.d.ts dist/cjs/index.d.cts", "build": "rollup -c && tsc -p tsconfig.esm.json && npm run build:cts", - "test:jsr": "npx jsr@latest publish --dry-run", "test": "mocha \"tests/**/*.test.js\"", - "test:coverage": "c8 npm test" + "test:coverage": "c8 npm test", + "test:jsr": "npx jsr@latest publish --dry-run", + "test:types": "tsc -p tests/types/tsconfig.json" }, "repository": { "type": "git", diff --git a/packages/object-schema/rollup.config.js b/packages/object-schema/rollup.config.js index 03a11e126..5b813a884 100644 --- a/packages/object-schema/rollup.config.js +++ b/packages/object-schema/rollup.config.js @@ -16,7 +16,7 @@ export default { plugins: [ copy({ targets: [ - { src: "src/types.ts", dest: "dist/cjs" }, + { src: "src/types.ts", dest: "dist/cjs", rename: "types.cts" }, { src: "src/types.ts", dest: "dist/esm" }, ], }), diff --git a/packages/object-schema/tests/types/cjs-import.test.cts b/packages/object-schema/tests/types/cjs-import.test.cts new file mode 100644 index 000000000..df767d4a3 --- /dev/null +++ b/packages/object-schema/tests/types/cjs-import.test.cts @@ -0,0 +1,10 @@ +/** + * @fileoverview CommonJS type import test for ObjectSchema package. + * @author Francesco Trotta + */ + +//----------------------------------------------------------------------------- +// Imports +//----------------------------------------------------------------------------- + +import "@eslint/object-schema"; diff --git a/packages/object-schema/tests/types/tsconfig.json b/packages/object-schema/tests/types/tsconfig.json new file mode 100644 index 000000000..638c0f3a5 --- /dev/null +++ b/packages/object-schema/tests/types/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "noEmit": true, + "rootDir": "../.." + }, + "include": [".", "../../dist"] +} diff --git a/packages/object-schema/tests/types/types.test.ts b/packages/object-schema/tests/types/types.test.ts new file mode 100644 index 000000000..1cd89a875 --- /dev/null +++ b/packages/object-schema/tests/types/types.test.ts @@ -0,0 +1,10 @@ +/** + * @fileoverview Type tests for ObjectSchema package. + * @author Francesco Trotta + */ + +//----------------------------------------------------------------------------- +// Imports +//----------------------------------------------------------------------------- + +import "@eslint/object-schema"; diff --git a/templates/package/package.json b/templates/package/package.json index 0427a900f..4bee178ec 100644 --- a/templates/package/package.json +++ b/templates/package/package.json @@ -28,9 +28,10 @@ "build:dedupe-types": "node ../../tools/dedupe-types.js dist/cjs/index.cjs dist/esm/index.js", "build:cts": "node ../../tools/build-cts.js dist/esm/index.d.ts dist/cjs/index.d.cts", "build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts", - "test:jsr": "npx jsr@latest publish --dry-run", "test": "mocha \"tests/**/*.test.js\"", - "test:coverage": "c8 npm test" + "test:coverage": "c8 npm test", + "test:jsr": "npx jsr@latest publish --dry-run", + "test:types": "tsc -p tests/types/tsconfig.json" }, "repository": { "type": "git", diff --git a/templates/package/tests/types/tsconfig.json b/templates/package/tests/types/tsconfig.json new file mode 100644 index 000000000..638c0f3a5 --- /dev/null +++ b/templates/package/tests/types/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "noEmit": true, + "rootDir": "../.." + }, + "include": [".", "../../dist"] +}