Skip to content

Commit a4707f1

Browse files
authored
feat: allow readonly array argument for IsIn IsNotIn validators (#600)
1 parent f5463f0 commit a4707f1

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/decorator/common/IsIn.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ export const IS_IN = "isIn";
66
/**
77
* Checks if given value is in a array of allowed values.
88
*/
9-
export function isIn(value: unknown, possibleValues: unknown[]): boolean {
9+
export function isIn(value: unknown, possibleValues: readonly unknown[]): boolean {
1010
return !(possibleValues instanceof Array) || possibleValues.some(possibleValue => possibleValue === value);
1111
}
1212

1313
/**
1414
* Checks if given value is in a array of allowed values.
1515
*/
16-
export function IsIn(values: any[], validationOptions?: ValidationOptions): PropertyDecorator {
16+
export function IsIn(values: readonly any[], validationOptions?: ValidationOptions): PropertyDecorator {
1717
return ValidateBy(
1818
{
1919
name: IS_IN,

src/decorator/common/IsNotIn.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ export const IS_NOT_IN = "isNotIn";
66
/**
77
* Checks if given value not in a array of allowed values.
88
*/
9-
export function isNotIn(value: unknown, possibleValues: unknown[]): boolean {
9+
export function isNotIn(value: unknown, possibleValues: readonly unknown[]): boolean {
1010
return !(possibleValues instanceof Array) || !possibleValues.some(possibleValue => possibleValue === value);
1111
}
1212

1313
/**
1414
* Checks if given value not in a array of allowed values.
1515
*/
16-
export function IsNotIn(values: any[], validationOptions?: ValidationOptions): PropertyDecorator {
16+
export function IsNotIn(values: readonly any[], validationOptions?: ValidationOptions): PropertyDecorator {
1717
return ValidateBy(
1818
{
1919
name: IS_NOT_IN,

test/functional/validation-functions-and-decorators.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ describe("IsNotEmpty", () => {
437437
});
438438

439439
describe("IsIn", () => {
440-
const constraint = ["foo", "bar"];
440+
const constraint = ["foo", "bar"] as const;
441441
const validValues = ["foo", "bar"];
442442
const invalidValues = ["foobar", "barfoo", ""];
443443

@@ -470,7 +470,7 @@ describe("IsIn", () => {
470470
});
471471

472472
describe("IsNotIn", () => {
473-
const constraint = ["foo", "bar"];
473+
const constraint = ["foo", "bar"] as const;
474474
const validValues = ["foobar", "barfoo", ""];
475475
const invalidValues = ["foo", "bar"];
476476

0 commit comments

Comments
 (0)