Giter VIP home page Giter VIP logo

Comments (4)

mcgrealife avatar mcgrealife commented on June 11, 2024 1

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.

eranhirsch avatar eranhirsch commented on June 11, 2024

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.

mcgrealife avatar mcgrealife commented on June 11, 2024

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.

eranhirsch avatar eranhirsch commented on June 11, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.