Skip to content

Add ArrayFlat type #1085

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

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

Conversation

Emiyaaaaa
Copy link
Collaborator

@Emiyaaaaa Emiyaaaaa requested a review from Copilot March 31, 2025 03:09
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request adds tests for the new ArrayFlat type and updates the README to document its behavior.

  • Added comprehensive tests in test-d/array-flat.ts to verify ArrayFlat across various array structures and depth parameters.
  • Updated readme.md to include an entry for ArrayFlat, describing its behavior similar to Array#flat().

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
test-d/array-flat.ts Added tests for the ArrayFlat type covering basic, nested, explicit depth, union, rest elements, and readonly arrays cases.
readme.md Added documentation for the ArrayFlat type.
Comments suppressed due to low confidence (3)

test-d/array-flat.ts:13

  • [nitpick] Consider renaming 'Arr' to a more descriptive name like 'NestedArray' to improve clarity.
type Arr = [[0, [1, [2, [3, [4, [5]]]]]]];

test-d/array-flat.ts:40

  • [nitpick] Consider clarifying the intent behind using 'Array<3>'. If it is meant to represent an array of the literal 3, a more descriptive type alias could improve readability.
expectType<ArrayFlat<[1, [2, ...Array<3>], 4]>>([1, 2, ...(null! as Array<3>), 4]);

readme.md:288

  • [nitpick] Consider expanding the description to clarify how 'ArrayFlat' handles explicit depths and union types, which may help users better understand its usage.
+ [`ArrayFlat`](source/array-flat.d.ts) - Creates a new array type by flattening an array to a specified depth, just like `Array#flat()`.

Copy link
Collaborator

@som-sm som-sm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Emiyaaaaa Added comments on the tests — haven’t reviewed the implementation yet.

@Emiyaaaaa Emiyaaaaa requested a review from som-sm April 30, 2025 09:27
@Emiyaaaaa Emiyaaaaa marked this pull request as draft April 30, 2025 09:41
@Emiyaaaaa Emiyaaaaa marked this pull request as ready for review April 30, 2025 09:58
@sindresorhus sindresorhus force-pushed the main branch 2 times, most recently from eabb987 to cc2b0f2 Compare May 8, 2025 08:21
@sindresorhus
Copy link
Owner

@Emiyaaaaa Can you fix the conflicts?

@Emiyaaaaa
Copy link
Collaborator Author

@Emiyaaaaa Can you fix the conflicts?

done

@sindresorhus
Copy link
Owner

I recommend copy-pasting the type into ChatGPT and ask it to "review, find bugs, and suggest improvements".

@Emiyaaaaa Emiyaaaaa requested a review from sindresorhus May 15, 2025 03:48
@Emiyaaaaa Emiyaaaaa requested a review from som-sm May 16, 2025 06:20
@som-sm
Copy link
Collaborator

som-sm commented May 16, 2025

Hi @Emiyaaaaa, I'll go through this peacefully sometime next week and add all comments at once!

@Emiyaaaaa Emiyaaaaa mentioned this pull request May 26, 2025
@som-sm som-sm mentioned this pull request Jun 5, 2025
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

Successfully merging this pull request may close these issues.

Proposal: Flat (equivalent to Array.prototype.flat())
3 participants