Giter VIP home page Giter VIP logo

Comments (2)

Harris-Miller avatar Harris-Miller commented on August 17, 2024 1

Your R.pipe<> typings is off by a bit: R.pipe<[Data[]], (number | null)[], number[]>(), but that's not the core problem

The problem here is due a combination of two things. First is the fact that typescript always picks the last overload when you pass a function as a prop. And R.reject has this:

export function reject<A, P extends A>(
  pred: (val: A) => val is P,
): {
  <B extends A>(list: readonly B[]): Array<Exclude<B, P>>;
  <B extends A>(dict: Record<string, B>): Record<string, Exclude<B, P>>;
};

R.reject(R.isNil) falls into this and so in your R.pipe, The R.reject is expecting a Record<string, B> and not a B[]. But R.pluck() is now, correctly, returning B[] (#71 fixed that, before it was returning an obj, not an array of objects like it should have, this is why you didn't have the problem before)

Since most use-cases for R.filter and R.reject is to pass a list and not an object, the list overload should come last. That's how it is on map as well. I actually have an open MR for this: #106. I'm going to add to that MR an update for R.reject as well

The second is how the new R.pluck is what I have been calling "the collapsing generics problem". You can read about it all here: #54

The tl;dr is because R.Pluck supports both and object and an array, the generic collapses to unknown, This is specifically due to the fact that there is more than one overload. If you use only one overload, the generic transfers. You can see this in action here: https://tsplay.dev/m3qojw

A short-term fix for you is to not use the curried varieties of those functions, and wrap them with arrow functions in your pipe

const extract = R.pipe<[Data[]], (number | null)[], number[]>(
  x => R.pluck("value", x),
  x => R.reject(R.isNil, x),
);

This is far from ideal, but will get around the typing problem until we can release a fix

from types.

nathan1530 avatar nathan1530 commented on August 17, 2024

Thank you for responding so quickly. I will use the workaround for now.

from types.

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.