Skip to content

Commit 42a30ea

Browse files
authored
fix: correct ValidationStrategy parameter types (#406)
1 parent f0fd9a2 commit 42a30ea

2 files changed

Lines changed: 44 additions & 9 deletions

File tree

packages/object-schema/src/validation-strategy.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
export class ValidationStrategy {
1313
/**
1414
* Validates that a value is an array.
15-
* @param {*} value The value to validate.
15+
* @param {unknown} value The value to validate.
1616
* @returns {void}
1717
* @throws {TypeError} If the value is invalid.
1818
*/
@@ -24,7 +24,7 @@ export class ValidationStrategy {
2424

2525
/**
2626
* Validates that a value is a boolean.
27-
* @param {*} value The value to validate.
27+
* @param {unknown} value The value to validate.
2828
* @returns {void}
2929
* @throws {TypeError} If the value is invalid.
3030
*/
@@ -36,7 +36,7 @@ export class ValidationStrategy {
3636

3737
/**
3838
* Validates that a value is a number.
39-
* @param {*} value The value to validate.
39+
* @param {unknown} value The value to validate.
4040
* @returns {void}
4141
* @throws {TypeError} If the value is invalid.
4242
*/
@@ -47,8 +47,8 @@ export class ValidationStrategy {
4747
}
4848

4949
/**
50-
* Validates that a value is a object.
51-
* @param {*} value The value to validate.
50+
* Validates that a value is an object.
51+
* @param {unknown} value The value to validate.
5252
* @returns {void}
5353
* @throws {TypeError} If the value is invalid.
5454
*/
@@ -59,8 +59,8 @@ export class ValidationStrategy {
5959
}
6060

6161
/**
62-
* Validates that a value is a object or null.
63-
* @param {*} value The value to validate.
62+
* Validates that a value is an object or null.
63+
* @param {unknown} value The value to validate.
6464
* @returns {void}
6565
* @throws {TypeError} If the value is invalid.
6666
*/
@@ -72,7 +72,7 @@ export class ValidationStrategy {
7272

7373
/**
7474
* Validates that a value is a string.
75-
* @param {*} value The value to validate.
75+
* @param {unknown} value The value to validate.
7676
* @returns {void}
7777
* @throws {TypeError} If the value is invalid.
7878
*/
@@ -84,7 +84,7 @@ export class ValidationStrategy {
8484

8585
/**
8686
* Validates that a value is a non-empty string.
87-
* @param {*} value The value to validate.
87+
* @param {unknown} value The value to validate.
8888
* @returns {void}
8989
* @throws {TypeError} If the value is invalid.
9090
*/

packages/object-schema/tests/types/types.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
type PropertyDefinition,
1919
type PropertyDefinitionWithSchema,
2020
type PropertyDefinitionWithStrategies,
21+
ValidationStrategy,
2122
} from "@eslint/object-schema";
2223

2324
//-----------------------------------------------------------------------------
@@ -134,6 +135,40 @@ MergeStrategy.assign({ a: 1 }, { a: "a" }) satisfies {
134135

135136
// #endregion MergeStrategy
136137

138+
//-----------------------------------------------------------------------------
139+
// Tests for ValidationStrategy
140+
//-----------------------------------------------------------------------------
141+
142+
// #region ValidationStrategy
143+
144+
const validateArray: CustomValidationStrategy = ValidationStrategy.array;
145+
const validateBoolean: CustomValidationStrategy = ValidationStrategy.boolean;
146+
const validateNumber: CustomValidationStrategy = ValidationStrategy.number;
147+
const validateObject: CustomValidationStrategy = ValidationStrategy.object;
148+
const validateObjectOptional: CustomValidationStrategy =
149+
ValidationStrategy["object?"];
150+
const validateString: CustomValidationStrategy = ValidationStrategy.string;
151+
const validateNonEmptyString: CustomValidationStrategy =
152+
ValidationStrategy["string!"];
153+
154+
ValidationStrategy.array([]);
155+
ValidationStrategy.boolean(true);
156+
ValidationStrategy.number(123);
157+
ValidationStrategy.object({ foo: 1 });
158+
ValidationStrategy["object?"](null);
159+
ValidationStrategy.string("foo");
160+
ValidationStrategy["string!"]("foo");
161+
162+
validateArray([]);
163+
validateBoolean(true);
164+
validateNumber(123);
165+
validateObject({ foo: 1 });
166+
validateObjectOptional(null);
167+
validateString("foo");
168+
validateNonEmptyString("foo");
169+
170+
// #endregion ValidationStrategy
171+
137172
//-----------------------------------------------------------------------------
138173
// Tests for PropertyDefinition
139174
//-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)