Skip to content

Commit d511d91

Browse files
lukashrochsdepold
andauthored
fix(types): allow any values in isIn validator (#12962)
* fix(types): allow any values in `isIn` validator * test(types): isIn/notIn validation type tests Co-authored-by: Sascha Depold <sdepold@users.noreply.github.com>
1 parent e4aff2f commit d511d91

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

types/lib/model.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,13 +1109,13 @@ export interface ModelValidateOptions {
11091109
/**
11101110
* check the value is not one of these
11111111
*/
1112-
notIn?: ReadonlyArray<readonly string[]> | { msg: string; args: ReadonlyArray<readonly string[]> };
1112+
notIn?: ReadonlyArray<readonly any[]> | { msg: string; args: ReadonlyArray<readonly any[]> };
11131113

11141114
/**
11151115
* check the value is one of these
11161116
*/
1117-
isIn?: ReadonlyArray<readonly string[]> | { msg: string; args: ReadonlyArray<readonly string[]> };
1118-
1117+
isIn?: ReadonlyArray<readonly any[]> | { msg: string; args: ReadonlyArray<readonly any[]> };
1118+
11191119
/**
11201120
* don't allow specific substrings
11211121
*/

types/test/validators.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { DataTypes, Model, Sequelize } from 'sequelize';
2+
3+
const sequelize = new Sequelize('mysql://user:user@localhost:3306/mydb');
4+
5+
/**
6+
* Test for isIn/notIn validation - should accept any[]
7+
*/
8+
class ValidatedUser extends Model {}
9+
ValidatedUser.init({
10+
name: {
11+
type: DataTypes.STRING,
12+
validate: {
13+
isIn: [['first', 1, null]]
14+
}
15+
},
16+
email: {
17+
type: DataTypes.STRING,
18+
validate: {
19+
notIn: [['second', 2, null]]
20+
}
21+
},
22+
}, { sequelize });

0 commit comments

Comments
 (0)