-
Notifications
You must be signed in to change notification settings - Fork 408
Add switch to disable the minItems/maxItems expanding #250
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
Comments
Hey there! What issue are you running into with those big generated types — what’s “unusable” about them? |
@bcherny Because the TS interfaces we generated are used for human reading too. |
Thanks for the context @YuJianrong, that does seem fair to me. @bradzacher What do you think of bailing out at some sensible number of maxItems (say, 5, 10, or 20) and falling back to a less safe array type, since big tuple types aren’t buying us much safety anyway (since you’re not going to manually construct 500-member tuple types, and are going to have to lug around the generated tuple type everywhere you use it for little benefit)? |
probably a good idea, yeah. It's probably pretty much impossible to provide values to those array types when they're that large as well. maybe like 10 is a good round number? feels like you wouldn't really be providing more tuple elements than that by hand. |
That sounds good to me. :) @YuJianrong want to contribute a fix for this? I would:
|
A switch to disable it completely would be very appreciated. We have a bunch of code written that expects |
We have a problem where the union tuple types it generates are hindering our ability to manipulate the array using map and reduce. type Test =
| [{ test1: boolean; test2: string }]
| [{ test1: boolean; test2: string }, { test1: boolean; test2: string }];
const arr = [
{ test1: true, test2: 'test2' },
{ test1: true, test2: 'test2' },
] as Test;
const test2 = arr.reduce(
(previousValue, currentValue) => previousValue && currentValue.test1, // error 1
true
);
const test3 = arr.map(val => val.test1); // error 2 I would suggest if typescript doesn't have proper support for min and max on arrays, then we shouldn't attempt to work around the issue with tuples. |
An option would be better. I think there are valid uses for using tuples, like validating the structure of configs. |
Thanks for the feedback everyone! Two issues here:
For (2), if someone wants to contribute an option |
@bradzacher Sure, I'm just being biased towards my use case. Thanks @bcherny, we'll try and find some bandwidth to implement your suggestion. |
In 0.7.0 a new PR #242 is merged to support minItems/maxItems for the array, this is great!
Until something like
In my JSON Schema...
This kind of schema generate a HUGE interface file which is not usable. May I ask can you add a flag to disable this feature or do some limitation like convert only for the case less than 5 items? Thanks.
The text was updated successfully, but these errors were encountered: