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 for flattenDeep #148

Closed
ssi02014 opened this issue Jul 10, 2024 · 2 comments · Fixed by #160
Closed

Support for flattenDeep #148

ssi02014 opened this issue Jul 10, 2024 · 2 comments · Fixed by #160

Comments

@ssi02014
Copy link
Contributor

Implement flattenDeep based on the recently added flatten.

/**
 * Utility type for recursively unpacking nested array types to extract the type of the innermost element 
 * 
 * ExtractNestedArrayType<(number | (number | number[])[])[]> // number
 * ExtractNestedArrayType<(boolean | (string | number[])[])[]>; // string | number | boolean
 */
type ExtractNestedArrayType<T> = T extends readonly (infer U)[] ? ExtractNestedArrayType<U> : T;

function flattenDeep<T>(arr: readonly T[]): ExtractNestedArrayType<T>[] {
  return flatten(arr, Infinity) as ExtractNestedArrayType<T>[];
}
@ssi02014 ssi02014 changed the title Support for flatDeep Support for flattenDeep Jul 10, 2024
@ssi02014
Copy link
Contributor Author

ssi02014 commented Jul 10, 2024

@raon0211 Can I proceed with the task? If you have any additional thoughts, I'd appreciate it. 🙏

@raon0211
Copy link
Collaborator

Sure! Looks really great.

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 a pull request may close this issue.

2 participants