-
Notifications
You must be signed in to change notification settings - Fork 70
refactor: prefer native methods to lodash where possible #328
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
Merged
+51
−74
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- _.endsWith -> String.endsWith
- _.concat -> Array.concat
- _.each -> Array.forEach
- _.filter -> Array.filter
- _.map -> Array.map
- _.some -> Array.some
- _.has -> `key in Object`
- _.defaults -> Object.assign
- _.get -> `?.` and `??` (optional chaining and nullish coalescing)
- refactor: replace fairly complicated `expandIncludeWithDirs` func to
just use a few simple `forEach`s
- not as FP anymore, more imperative, but much simpler to read IMO
- refactor: add a `getDiagnostics` helper to DRY up some code
- also aids readability IMO
- a few places are still using lodash, but this paves the way toward
removing it or replacing it with much smaller individual deps
- _.compact still used because Array.filter heavily complicates the
type-checking currently
- _.isFunction still used because while it's a one-liner natively,
need to import a function in several places
- also the package `lodash.isFunction` is lodash v3 and quite
different from the v4 implementation, so couldn't replace with it
unfortunately
- _.merge is a deep merge, so there's no native version of this
- but we may remove deep merges entirely in the future (as tsconfig
doesn't quite perform a deep merge), or could replace this with a
smaller `lodash.merge` package or similar
- see also https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore
99b8803 to
d0fcc97
Compare
This was referenced May 31, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
kind: internal
Changes only affect the internals, and _not_ the public API or external-facing docs
scope: dependencies
Issues or PRs about updating a dependency
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Replace most (not all)
lodashmethods with native methodsDetails
_.endsWith-> String.endsWith_.concat-> Array.concat_.each-> Array.forEach_.filter-> Array.filter_.map-> Array.map_.some-> Array.some_.has->key in Object_.defaults-> Object.assign_.get->?.and??(optional chaining and nullish coalescing)refactor: replace fairly complicated
expandIncludeWithDirsfunc to just use a few simpleforEachsrefactor: add a
getDiagnosticshelper to DRY up some codea few places are still using lodash, but this paves the way toward removing it or replacing it with much smaller individual deps
_.compactstill used because Array.filter heavily complicates the type-checking currently_.isFunctionstill used because while it's a one-liner natively, need to import a function in several placeslodash.isFunctionis lodash v3 and quite different from the v4 implementation, so couldn't replace with it unfortunately_.mergeis a deep merge, so there's no native version of thistsconfigOverridewhere TS does so -- matchtsconfigextends#86 (comment)), or could replace this with a smallerlodash.mergepackage or similarsee also https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore
Review Notes
Unit tests still pass, so other than looking equivalent and typing equivalently, usage still works equivalently (caveat though:
tscacheandindexaren't yet tested)