Skip to content

Commit a902bc4

Browse files
authored
fix: fix config-array and object-schema types (#294)
1 parent ddc8577 commit a902bc4

File tree

15 files changed

+95
-14
lines changed

15 files changed

+95
-14
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ jobs:
7575
run: |
7676
npm run test:types
7777
78+
- name: Test types (object-schema)
79+
working-directory: packages/object-schema
80+
run: |
81+
npm run test:types
82+
83+
- name: Test types (config-array)
84+
working-directory: packages/config-array
85+
run: |
86+
npm run test:types
87+
7888
- name: Test types (config-helpers)
7989
working-directory: packages/config-helpers
8090
run: |

packages/config-array/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@
3636
"build:cts": "node ../../tools/build-cts.js dist/esm/index.d.ts dist/cjs/index.d.cts",
3737
"build:std__path": "rollup -c rollup.std__path-config.js && node fix-std__path-imports",
3838
"build": "rollup -c && npm run build:dedupe-types && tsc -p tsconfig.esm.json && npm run build:cts && npm run build:std__path",
39-
"test:jsr": "npx jsr@latest publish --dry-run",
4039
"pretest": "npm run build",
4140
"test": "mocha \"tests/**/*.test.js\"",
42-
"test:coverage": "c8 npm test"
41+
"test:coverage": "c8 npm test",
42+
"test:jsr": "npx jsr@latest publish --dry-run",
43+
"test:types": "tsc -p tests/types/tsconfig.json"
4344
},
4445
"keywords": [
4546
"configuration",

packages/config-array/rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default {
1616
plugins: [
1717
copy({
1818
targets: [
19-
{ src: "src/types.ts", dest: "dist/cjs" },
19+
{ src: "src/types.ts", dest: "dist/cjs", rename: "types.cts" },
2020
{ src: "src/types.ts", dest: "dist/esm" },
2121
],
2222
}),

packages/config-array/rollup.std__path-config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ export default [
77
input: resolve("@jsr/std__path/posix"),
88
output: [
99
{
10+
banner: "// @ts-nocheck",
1011
file: "./dist/cjs/std__path/posix.cjs",
1112
format: "cjs",
1213
},
1314
{
15+
banner: "// @ts-nocheck",
1416
file: "./dist/esm/std__path/posix.js",
1517
format: "esm",
1618
},
@@ -20,10 +22,12 @@ export default [
2022
input: resolve("@jsr/std__path/windows"),
2123
output: [
2224
{
25+
banner: "// @ts-nocheck",
2326
file: "./dist/cjs/std__path/windows.cjs",
2427
format: "cjs",
2528
},
2629
{
30+
banner: "// @ts-nocheck",
2731
file: "./dist/esm/std__path/windows.js",
2832
format: "esm",
2933
},

packages/config-array/src/config-array.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ import { filesAndIgnoresSchema } from "./files-and-ignores-schema.js";
2020
// Types
2121
//------------------------------------------------------------------------------
2222

23-
/** @typedef {import("@eslint/object-schema").PropertyDefinition} PropertyDefinition */
24-
/** @typedef {import("@eslint/object-schema").ObjectDefinition} ObjectDefinition */
2523
/** @typedef {import("./types.ts").ConfigObject} ConfigObject */
2624
/** @typedef {import("minimatch").IMinimatchStatic} IMinimatchStatic */
2725
/** @typedef {import("minimatch").IMinimatch} IMinimatch */
28-
/** @typedef {import("@jsr/std__path")} PathImpl */
26+
/** @import * as PathImpl from "@jsr/std__path" */
2927

3028
/*
3129
* 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";
3432
* for `ObjectSchema`. To work around that, we just import the type manually
3533
* and give it a different name to use in the JSDoc comments.
3634
*/
37-
/** @typedef {import("@eslint/object-schema").ObjectSchema} ObjectSchemaInstance */
35+
/** @typedef {ObjectSchema} ObjectSchemaInstance */
3836

3937
//------------------------------------------------------------------------------
4038
// Helpers
@@ -968,7 +966,8 @@ export class ConfigArray extends Array {
968966
* @param {Object} config The config to finalize.
969967
* @returns {Object} The finalized config.
970968
*/
971-
[ConfigArraySymbol.finalizeConfig](config) {
969+
// Cast key to `never` to prevent TypeScript from adding the signature `[x: symbol]: (config: any) => any` to the type of the class.
970+
[/** @type {never} */ (ConfigArraySymbol.finalizeConfig)](config) {
972971
return config;
973972
}
974973

@@ -980,7 +979,8 @@ export class ConfigArray extends Array {
980979
* @param {Object} config The config to preprocess.
981980
* @returns {Object} The config to use in place of the argument.
982981
*/
983-
[ConfigArraySymbol.preprocessConfig](config) {
982+
// Cast key to `never` to prevent TypeScript from adding the signature `[x: symbol]: (config: any) => any` to the type of the class.
983+
[/** @type {never} */ (ConfigArraySymbol.preprocessConfig)](config) {
984984
return config;
985985
}
986986

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @fileoverview CommonJS type import test for Config Array package.
3+
* @author Francesco Trotta
4+
*/
5+
6+
//-----------------------------------------------------------------------------
7+
// Imports
8+
//-----------------------------------------------------------------------------
9+
10+
import "@eslint/config-array";
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"noEmit": true,
5+
"rootDir": "../.."
6+
},
7+
"include": [".", "../../dist"]
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @fileoverview Type tests for Config Array package.
3+
* @author Francesco Trotta
4+
*/
5+
6+
//-----------------------------------------------------------------------------
7+
// Imports
8+
//-----------------------------------------------------------------------------
9+
10+
import "@eslint/config-array";

packages/object-schema/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
"scripts": {
2828
"build:cts": "node ../../tools/build-cts.js dist/esm/index.d.ts dist/cjs/index.d.cts",
2929
"build": "rollup -c && tsc -p tsconfig.esm.json && npm run build:cts",
30-
"test:jsr": "npx jsr@latest publish --dry-run",
3130
"test": "mocha \"tests/**/*.test.js\"",
32-
"test:coverage": "c8 npm test"
31+
"test:coverage": "c8 npm test",
32+
"test:jsr": "npx jsr@latest publish --dry-run",
33+
"test:types": "tsc -p tests/types/tsconfig.json"
3334
},
3435
"repository": {
3536
"type": "git",

packages/object-schema/rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default {
1616
plugins: [
1717
copy({
1818
targets: [
19-
{ src: "src/types.ts", dest: "dist/cjs" },
19+
{ src: "src/types.ts", dest: "dist/cjs", rename: "types.cts" },
2020
{ src: "src/types.ts", dest: "dist/esm" },
2121
],
2222
}),

0 commit comments

Comments
 (0)