question: how to validate 2D arrays?
See original GitHub issueHello,
I have something like this
@Type
is from class-transformer. I tried to search for the issues but I could not find anything.
export class Child {
@IsDefined()
@IsString()
@IsNotEmpty()
name: string;
}
export class Parent {
@IsArray()
@IsNotEmpty()
@Type((type) => Child)
@ValidateNested()
children: Child[][];
}
const parent = new Parent();
let res;
// I need `as any` because I'm using strictNullChecks
parent.children= 123 as any;
res = validateSync(parent); // this fails
parent.children= [] as any;
res = validateSync(parent); // this passes
parent.children= [[]] as any;
res = validateSync(parent); // this passes
parent.children= [[ { name: null } ]] as any;
res = validateSync(parent); // this passes
Even if the type Child
is changed to JS native types like number
or string
. How can I validate something like this?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Validating elements of a 2D array - java - Stack Overflow
You have three problems here, two of which are critical. First, if you want to iterate over each subarray, test its length, not...
Read more >Check for possible path in 2D matrix - GeeksforGeeks
Given a 2D array(m x n). The task is to check if there is any path from top left to bottom right. In...
Read more >Validate if string is correctly formed 2D array - Sololearn
What I'd like to do atm is parse a user input string to check if it is a valid 2D array.
Read more >2. Given an 2D array of n xn, write a function to | Chegg.com
Question : 2. Given an 2D array of n xn, write a function to validate whether that is a symmetric matrix or not....
Read more >How do I do input validation for 2D array in C++? - Quora
It depends upon how the 2 dimensional array was constructed. You must follow the actual layout of the data to properly set the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Not really sure how that would work, can you point us in the right direction here?
As mentioned by others, you can use a custom validator for this.