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

refactor(core): replace our own 1-level flatten by the native one #9902

Merged

Conversation

micalevisk
Copy link
Member

@micalevisk micalevisk commented Jul 9, 2022

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the new behavior?

node12 has Array.prototype.flat method. See https://node.green/#ES2019-features-Array-prototype--flat--flatMap--Array-prototype-flat

thus we don't need to write this logic anymore.

I didn't changed the flatten on @nestjs/common because it is being used by other nestjs packages that didn't bumped their major version (ie., they still supports node10, I guess)

image

export function flatten<T extends Array<unknown> = any>(
arr: T,
): T extends Array<infer R> ? R : never {
const flat = [].concat(...arr);
return flat.some(Array.isArray) ? flatten(flat) : flat;
}

the above could be written like this: arr.flat(Infinity)


Also, I've looked at every JS feature that was added in node12 (taking this table https://node.green) to see if there is something that we could update in this repo. Didn't find other feature tho.

Does this PR introduce a breaking change?

  • Yes
  • No

@coveralls
Copy link

Pull Request Test Coverage Report for Build fe4257cc-19e3-48d4-890d-7603612ac0c3

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 93.91%

Totals Coverage Status
Change from base Build 89137624-bda6-49c5-bbc7-d5e6f900f6cc: 0.0%
Covered Lines: 6029
Relevant Lines: 6420

💛 - Coveralls

@kamilmysliwiec kamilmysliwiec merged commit 9f90706 into nestjs:master Jul 11, 2022
@kamilmysliwiec
Copy link
Member

lgtm

@micalevisk micalevisk deleted the refactor/use-builtin-node12-functions branch July 11, 2022 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants