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

Support minItems and maxItems schema properties #14

Open
fedorov-xyz opened this issue Feb 18, 2021 · 4 comments
Open

Support minItems and maxItems schema properties #14

fedorov-xyz opened this issue Feb 18, 2021 · 4 comments

Comments

@fedorov-xyz
Copy link
Contributor

fedorov-xyz commented Feb 18, 2021

Generate tuple from minItems and maxItems:

minItems:

"propertyName": {
  "type": "array",
  "items": {
    "type": "string"
  },
  "minItems": 2
}
propertyName: [string, string, ...string[]];

maxItems:

"propertyName": {
  "type": "array",
  "items": {
    "type": "string"
  },
  "maxItems": 4
}
propertyName: [string, string, string, string];
@fedorov-xyz fedorov-xyz changed the title Support minItems schema property Support minItems and maxItems schema properties Feb 18, 2021
@gyzerok
Copy link

gyzerok commented Sep 17, 2021

Тут, кажется, во втором случае некорректный пример. Должно быть [string | undefiend, string | undefined, ...].

А если есть одновременно и мин и макс, тогда можно написать:

// min - 2
// max - 3

[string, string, string | undefined]

@gyzerok
Copy link

gyzerok commented Sep 17, 2021

Хотя нет, даже так некорректно, потому что может получиться ['foo', undefiend, 'bar']. Корректно:

[] | [string] | [string, string] | [string, string, ...] ...

@fedorov-xyz
Copy link
Contributor Author

Хотя нет, даже так некорректно, потому что может получиться ['foo', undefiend, 'bar']. Корректно:

[] | [string] | [string, string] | [string, string, ...] ...

Ух, тогда это может в дико огромную запись превратиться.

@SevereCloud
Copy link
Contributor

Слепил такое - Playground

// minItems - 1
const items: [string, ...string[]]

// maxItems - 3
// const items: [] | [string] | [string, string] | [string, string, string]
const items: Tuple<string, RangeOf<3>> 

// minItems - 1
// maxItems - 3
// const items: [string] | [string, string] | [string, string, string]
const items: Tuple<string, RangeOf2<1,3>> 

Из проблем - нужен typescript выше версии v4.1.0

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

3 participants