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

Empty bundle prohibition is inconvenient for TypeScript users #11801

Closed
andersk opened this issue Oct 24, 2020 · 1 comment · Fixed by #11862
Closed

Empty bundle prohibition is inconvenient for TypeScript users #11801

andersk opened this issue Oct 24, 2020 · 1 comment · Fixed by #11862

Comments

@andersk
Copy link

andersk commented Oct 24, 2020

Feature request

What is the expected behavior?
The EntryItem type should be string[] | string, not [string, ...string[]] | string.

What is motivation or use case for adding/changing the behavior?
The [string, ...string[]] type is annoying to work with in TypeScript, because it’s incompatible with almost every nontrivial way you might compute the entry parameter other than writing it out literally. For example, using filter or map or importing from a .json file all give you a string[], which cannot be assigned to [string, ...string[]] without an unchecked cast, even if the programmer “knows” the result will be nonempty.

How should this be implemented in your opinion?
Either remove the relevant "minItems": 1 from schemas/WebpackOptions.json, or configure json-schema-to-typescript with ignoreMinAndMaxItems.

Are you willing to work on this yourself?
yes

@alexander-akait
Copy link
Member

Yes, PR welcome

andersk added a commit to andersk/webpack that referenced this issue Oct 28, 2020
There may be no practical reason to use an empty array here, but it’s not
harmful, and allowing it makes the TypeScript typings more convenient,
e.g. string[] instead of [string, ...string[]].

The [string, ...string[]] type was annoying to work with because it’s
incompatible with almost every nontrivial way you might compute the value other
than writing it out literally. For example, using filter or map or importing
from a .json file all give you a string[], which cannot be assigned to [string,
...string[]] without an unchecked cast, even if the programmer “knows” the
result will be nonempty.

Fixes webpack#11801.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
andersk added a commit to andersk/webpack that referenced this issue Oct 28, 2020
There may be no practical reason to use an empty array here, but it’s not
harmful, and allowing it makes the TypeScript typings more convenient,
e.g. string[] instead of [string, ...string[]].

The [string, ...string[]] type was annoying to work with because it’s
incompatible with almost every nontrivial way you might compute the value other
than writing it out literally. For example, using filter or map or importing
from a .json file all give you a string[], which cannot be assigned to [string,
...string[]] without an unchecked cast, even if the programmer “knows” the
result will be nonempty.

Fixes webpack#11801.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
andersk added a commit to andersk/webpack that referenced this issue Oct 28, 2020
There may be no practical reason to use an empty array here, but it’s not
harmful, and allowing it makes the TypeScript typings more convenient,
e.g. string[] instead of [string, ...string[]].

The [string, ...string[]] type was annoying to work with because it’s
incompatible with almost every nontrivial way you might compute the value other
than writing it out literally. For example, using filter or map or importing
from a .json file all give you a string[], which cannot be assigned to [string,
...string[]] without an unchecked cast, even if the programmer “knows” the
result will be nonempty.

Fixes webpack#11801.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
sokra added a commit that referenced this issue Oct 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants