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

Non Empty Array Type #181

Open
Leandro-Albano opened this issue Nov 6, 2022 · 2 comments
Open

Non Empty Array Type #181

Leandro-Albano opened this issue Nov 6, 2022 · 2 comments
Assignees

Comments

@Leandro-Albano
Copy link

Leandro-Albano commented Nov 6, 2022

Is your feature request related to a real problem or use-case?

Use-case. Where we need an non empty array to be provided.

Describe a solution including usage in code example

type NonEmptyArray<T> = [T, ...T[]];

const invalid: NonEmptyArray<string> = []; // Type '[]' is not assignable to type 'NonEmptyArray<string>'. Source has 0 element(s) but target requires 1.
const valid: NonEmptyArray<string> = ['']; // no error

Who does this impact? Who is this for?

Typescript users that need to type check for non empty arrays.

Describe alternatives you've considered (optional)

The alternative is to document the method/func/prop to notify the consumers that it needs a non empty array.

Additional context (optional)

@Leandro-Albano
Copy link
Author

I would be happy to submit a PR for that if approved!

@piotrwitek
Copy link
Owner

Hey @Leandro-Albano , sorry for the late reply got some personal issues.
Yes, it looks great from my perspective, please feel free to open PR and let me know to review it. Thanks

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

2 participants