Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ValidateNested support multi-dimensional arrays #539

Merged
merged 1 commit into from Mar 28, 2020

Conversation

jBouyoud
Copy link
Contributor

@jBouyoud jBouyoud commented Mar 3, 2020

@NoNameProvided This PR aims to fix #538

@jBouyoud
Copy link
Contributor Author

@vlapo

Copy link
Contributor

@vlapo vlapo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good for me. Could you please add some note to docs about multidimensional arrays?

mySubSubClasses: MySubClass[][];

@ValidateNested()
mySubSubSubClasses: MySubClass[][][];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it work with tuples too? myTupleClasses: [MyClass1, MyClass2];

Copy link
Contributor

@vlapo vlapo Mar 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is about multidimensional arrays. myTupleClasses: [MyClass1, MyClass2]; is basically simple array (we already support simple arrays). But we validate only items of array. So for example this will pass:

class Tuple1 {
  @IsNumber()
  num: number;
}

class Tuple2 {
  @IsString()
  name: string;
}

class Test {

  @ValidateNested()
  tuples: [Tuple1, Tuple2];

}

const t = new Test();
t.tuples = [new Tuple1(), new Tuple1() as any];
t.tuples[0].num = 2 as any;
(t.tuples[1] as any).num = 2 as any;

console.log(validateSync(t));

@jBouyoud jBouyoud force-pushed the fix-nested-nested-validation branch from 4a50e67 to 89d7c82 Compare March 27, 2020 07:17
@jBouyoud
Copy link
Contributor Author

I've added a very simple example about multi dimensional array.
Let me know if that not enough

@vlapo vlapo self-requested a review March 28, 2020 20:54
@vlapo
Copy link
Contributor

vlapo commented Mar 28, 2020

This is not full support of multi-dimensional arrays but at least @ValidateNested works now.
So I will not close #538 and track multi-dimensional support there.
Thank you!

@vlapo vlapo changed the title Fix recursive array like validation fix: ValidateNested support multi-dimensional arrays Mar 28, 2020
@vlapo vlapo merged commit 62678e1 into typestack:master Mar 28, 2020
@jBouyoud jBouyoud deleted the fix-nested-nested-validation branch March 30, 2020 05:53
@github-actions
Copy link

github-actions bot commented Aug 3, 2020

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

feat: support multi-dimensional arrays
4 participants