Comments (4)
Wow, major "click" moment. Thanks as always @eranhirsch, your support is rare and appreciated.
Also, thanks for the new R.isNonNull release, I am updating Remeda now!
from remeda.
Don't recreate the arrow functions, use the remeda functions directly otherwise you are converting a type-predicate to a regular boolean returning function (this is just how typescript types the arrow function, it's not because of Remeda)
R.filter(R.isNonNull)
from remeda.
I encountered a similar case and am struggling to apply your answer when the input is an array of objects:
This R.filter only checks if the object isNonNull, not the object's values
R.pipe(
[{ number: 1 }, { number: null }],
R.filter(R.isNonNull),
R.sortBy((x) => x.number) // Type 'null' is not assignable to type 'Comparable'.
Maybe you have a better way. Thank you as always @eranhirsch
from remeda.
Your filter is not doing what you think it's doing. Check out your IDE's typehint tooltips. You are filtering objects which are null, not the prop within them. Remeda doesn't have (at least rn) a way to filter and narrow the type of a prop within an object. You'll need to write something yourself.
R.pipe(
[{ number: 1 }, { number: null }],
R.filter(hasNumber),
R.sortBy(prop('number')),
);
function hasNumber(obj: { number: number | null }): obj is { number: number } {
return obj.number !== null;
}
from remeda.
Related Issues (20)
- Missing function: isEmpty HOT 4
- Option to filter docs by types HOT 2
- TS errors in curried `pick` HOT 2
- Question: Example removing undefined from array? HOT 2
- The sample function doesn't seem to infer types correctly HOT 1
- Helper to check if all object values are Truthy? HOT 2
- I cannot understand doc for sortBy HOT 3
- Feature Request: swap element in Array HOT 1
- Nested object to object of key tuples HOT 1
- it would be cool if it works HOT 4
- Generate testing suites using a ChatGPT-4 CLI wrapper HOT 1
- lint for correctness HOT 1
- `filterValues` for filtering objects HOT 2
- Unexpected `dropLast` behavior with negative `n`. HOT 2
- `equals` and recursive structures leads to `Maximum call stack size exceeded` HOT 5
- Request for new binary search based indexing functions HOT 5
- Problem with `mapValues` types HOT 6
- `pathOr` has broken types HOT 11
- feature request: xor HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from remeda.