Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Typescript Standard | 30 | 16 | 33 | 4 years ago | 44 | March 07, 2018 | other | TypeScript | ||
Zero-configuration TypeScript 2 & 3 Standard Validation | ||||||||||
Tslint Angular Security | 18 | 5 years ago | 5 | November 30, 2018 | TypeScript | |||||
TSLint rules for Angular | ||||||||||
Class Validator Rule | 9 | 3 years ago | TypeScript | |||||||
tslint rule for class-validator | ||||||||||
Tslint.tmbundle | 2 | 6 years ago | bsd-3-clause | TypeScript | ||||||
Integrates the TSLint TypeScript validator with TextMate | ||||||||||
Tslint Import Rules | 2 | 4 years ago | mit | TypeScript | ||||||
Set of TSLint rules that help validate proper imports. |
It is possible to do strongly typed validation with class-validator.
This class
enum Color { Red, Green, Blue }
class SomeObject {
string?: string;
}
class Model {
color: Color;
string: string;
number: number;
boolean: boolean;
date: Date;
stringArray: string[];
numberArray: number[];
booleanArray: boolean[];
dateArray: Date[];
enumArray: Color[];
object: SomeObject;
objectArray: SomeObject[];
}
Should decorate like:
enum Color { Red, Green, Blue }
class SomeObject {
@IsOptional()
@IsString()
string?: string;
}
class Model {
@IsEnum(Color)
color: Color;
@IsString()
string: string;
@IsNumber()
number: number;
@IsBoolean()
boolean: boolean;
@IsDate()
date: Date;
@IsString({ each: true })
stringArray: string[];
@IsNumber({},{ each: true })
numberArray: number[];
@IsBoolean({ each: true })
booleanArray: boolean[];
@IsDate({ each: true })
dateArray: Date[];
@IsEnum(Color,{ each: true })
enumArray: Color[];
@ValidateNested()
object: SomeObject;
@ValidateNested({ each: true })
objectArray: SomeObject[];
}
This rule reminds you to add the correct decorator and can fix your models.
npm i tslint-class-validator-rule -D
Add tslint configoration to root of your models folder
{
"rulesDirectory": ["tslint-class-validator-rule"],
"rules": {
"no-property-without-decorator":true
}
}
Fix
tslint -p . --fix
app.useGlobalPipes(new ValidationPipe({ forbidUnknownValues: true }));