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

feat: better typing on filterMap for use with predicates #106

Merged
merged 1 commit into from
Jan 8, 2021

Conversation

wschurman
Copy link
Member

Why

When a map is filtered with a predicate, if the predicate signals a type using the is operator, then the resulting map should be have values of the type of the predicate result. For instance, if the type Map<string, string | null> is filtered with a truthy predicate, then the return type of filterMap should be Map<string, string>.

Array accomplishes this with a function declaration overload: https://github.com/microsoft/TypeScript/blob/master/lib/lib.es5.d.ts#L1176

How

Add a function declaration overload.

Test Plan

yarn tsc, also run new test.

@codecov
Copy link

codecov bot commented Jan 8, 2021

Codecov Report

Merging #106 (5e0f697) into master (8354741) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #106   +/-   ##
=======================================
  Coverage   94.95%   94.95%           
=======================================
  Files          66       66           
  Lines        1624     1624           
  Branches      195      195           
=======================================
  Hits         1542     1542           
  Misses         80       80           
  Partials        2        2           
Flag Coverage Δ
integration 94.95% <100.00%> (ø)
unittest 94.95% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/entity/src/utils/collections/maps.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8354741...5e0f697. Read the comment docs.

@wschurman wschurman merged commit 01b3bfe into master Jan 8, 2021
@wschurman wschurman deleted the @wschurman/better-types branch January 8, 2021 18:02
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.

2 participants