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

[Feature]: ArraySchema.from #166

Open
hunkydoryrepair opened this issue Mar 7, 2024 · 0 comments
Open

[Feature]: ArraySchema.from #166

hunkydoryrepair opened this issue Mar 7, 2024 · 0 comments

Comments

@hunkydoryrepair
Copy link

Description & Use case

Ability to initialize an ArraySchema from an iterator or a regular array (Array<>)

Using spread operator like this: new ArraySchema<string>(...arrayofstrings) can lead to a stack overflow error.
This would also allow constructing from things like map.keys() which cannot be spread, and the current solution is only to construct an iterator and add to ArraySchema one at a time.

Optional: Proposed API

A static method from in ArraySchema could accept any object with a forEach iterator.

Alternatively, could make the constructor or push function smarter. Since ArraySchema is typed, we could know that when ArraySchema<string>.push is called with a Array<string>, that it should concat instead of attempting to just push on the array as if it was a string. This is less consistent with Array<>, but unlike with Array<> the ArraySchema currently throws an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant