class-validator @ValidateNested()
issue with entities from local installed package.
cd tsc-package && npm i
npm build
cd tsc-app && npm i
npm start
export class ParentDto {
@IsString()
@IsNotEmpty()
name: string
@IsArray()
@ArrayNotEmpty()
@ValidateNested({ each: true })
@Type(() => ChildDto)
children: ChildDto[]
}
export class ChildDto {
@IsString()
@IsNotEmpty()
name: string
@IsString()
@IsNotEmpty()
age: string
}
const raw = {
name: 'parent name',
children: [
{}
]
}
local errors
[
{
"target": {
"name": "parent name",
"children": [
{}
]
},
"value": [
{}
],
"property": "children",
"children": [
{
"target": [
{}
],
"value": {},
"property": "0",
"children": [
{
"target": {},
"property": "name",
"children": [],
"constraints": {
"isNotEmpty": "name should not be empty",
"isString": "name must be a string"
}
},
{
"target": {},
"property": "age",
"children": [],
"constraints": {
"isNotEmpty": "age should not be empty",
"isString": "age must be a string"
}
}
]
}
]
}
]
package errors
[]
local errors
[
{
"target": {
"name": "parent name",
"children": [
{}
]
},
"value": [
{}
],
"property": "children",
"children": [
{
"target": [
{}
],
"value": {},
"property": "0",
"children": [
{
"target": {},
"property": "name",
"children": [],
"constraints": {
"isNotEmpty": "name should not be empty",
"isString": "name must be a string"
}
},
{
"target": {},
"property": "age",
"children": [],
"constraints": {
"isNotEmpty": "age should not be empty",
"isString": "age must be a string"
}
}
]
}
]
}
]
package errors
[
{
"target": {
"name": "parent name",
"children": [
{}
]
},
"value": [
{}
],
"property": "children",
"children": [
{
"target": [
{}
],
"value": {},
"property": "0",
"children": [
{
"target": {},
"property": "name",
"children": [],
"constraints": {
"isNotEmpty": "name should not be empty",
"isString": "name must be a string"
}
},
{
"target": {},
"property": "age",
"children": [],
"constraints": {
"isNotEmpty": "age should not be empty",
"isString": "age must be a string"
}
}
]
}
]
}
]