-
-
Notifications
You must be signed in to change notification settings - Fork 679
ExcludeRestElement: Fix generic assignability with arrays
#1274
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
Changes from 2 commits
8bba628
dc490d4
0aed831
41a905f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||||||||||||||||||||||||||||||||||||||
| import type {SplitOnRestElement} from './split-on-rest-element.d.ts'; | ||||||||||||||||||||||||||||||||||||||||||
| import type {IsArrayReadonly} from './internal/array.d.ts'; | ||||||||||||||||||||||||||||||||||||||||||
| import type {UnknownArray} from './unknown-array.d.ts'; | ||||||||||||||||||||||||||||||||||||||||||
| import type {IfNotAnyOrNever} from './internal/type.d.ts'; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||||||
| Create a tuple with the [`rest`](https://www.typescriptlang.org/docs/handbook/2/objects.html#tuple-types) element removed. | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -26,13 +27,14 @@ type T4 = ExcludeRestElement<[number, string]>; | |||||||||||||||||||||||||||||||||||||||||
| @see {@link SplitOnRestElement} | ||||||||||||||||||||||||||||||||||||||||||
| @category Array | ||||||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||||||
| export type ExcludeRestElement<Array_ extends UnknownArray> = | ||||||||||||||||||||||||||||||||||||||||||
| export type ExcludeRestElement<Array_ extends UnknownArray> = IfNotAnyOrNever<Array_, | ||||||||||||||||||||||||||||||||||||||||||
| SplitOnRestElement<Array_> extends infer Result | ||||||||||||||||||||||||||||||||||||||||||
| ? Result extends readonly UnknownArray[] | ||||||||||||||||||||||||||||||||||||||||||
| ? IsArrayReadonly<Array_> extends true | ||||||||||||||||||||||||||||||||||||||||||
| ? Readonly<[...Result[0], ...Result[2]]> | ||||||||||||||||||||||||||||||||||||||||||
| : [...Result[0], ...Result[2]] | ||||||||||||||||||||||||||||||||||||||||||
| : Result | ||||||||||||||||||||||||||||||||||||||||||
| : never; | ||||||||||||||||||||||||||||||||||||||||||
| : never | ||||||||||||||||||||||||||||||||||||||||||
| : never | ||||||||||||||||||||||||||||||||||||||||||
| >; | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+30
to
+38
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please consider using
Suggested change
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This was only for recursive types.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And, if used properly, |
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| export {}; | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is
Result(and notnever), then the compiler thinks the type produces something more than just arrays.