Giter VIP home page Giter VIP logo

Comments (2)

Harris-Miller avatar Harris-Miller commented on July 1, 2024 1

Hi there thanks for the issue. I found out what was going on here. For types-ramda we updated to the latest ts-toolkit as that was needed to fix some existing types. The way the mergeAll was previously types used type functions from ts-toolkit that no longer exists. So we had to re-type them.

The current type is this:

export function mergeAll<O extends object, Os extends readonly object[]>(list: [O, ...Os]): _.O.Assign<O, Os>;

_.O.Assign is defined here and as the name suggests, a type for Object.assign, which is exactly what mergeAll is under the hood

Our tests included the following

const foo = { foo: 'foo' };
const bar = { bar: 'bar' };
const foo2 = { foo: 2 };

expectType<{ foo: string; }>(mergeAll([foo]));
expectType<{ foo: string; bar: string; }>(mergeAll([foo, bar]));
expectType<{ foo: number; }>(mergeAll([foo, foo2]));

Those tests, as it turns out, only account for passing in array literals of either the same or different types. It turns out, that when you pass in an Array<any> or any[], the typings break down. It breaks down specifically because when you have Array<any> or any[], [O, ...Os] cannot be inferred in the same way when passing an array literal or tuple, Giving you the Source provides no match for required element at position 0 in target. error

Fortunately, this is an easy fix. Since when you mergeAll an Array<T> you simple get back T. Which means the solution is just to add this overload

export function mergeAll<T>(list: readonly T[]): T;

MR here: #23
I'll try to get this merged and released today for you

from types.

swemail avatar swemail commented on July 1, 2024

Thank you for the swift fix an in depth explanation 💥

from types.

Related Issues (17)

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.