ramda / types

MIT License
27 stars 22 forks source link

partition typing broken with interface and object #132

Open davetapley opened 1 day ago

davetapley commented 1 day ago

Not sure if regression. Works at runtime, but last partition doesn't type check:

import { filter, partition, test, where } from "ramda";

export interface IFoo {
    bar: string;
}
const check = where({ bar: test(/fo/) })

const dataList: IFoo[] = [{ bar: "foo" }, { bar: "baz" }]
const dataObj: { [id: string]: IFoo } = { one: { bar: "foo" }, two: { bar: "baz" } }

describe("whereUnit", () => {
    it("works with filter", () => {
        expect(filter(check, dataList)).toEqual([{ bar: "foo" }])
        expect(filter(check, dataObj)).toEqual({ one: { bar: "foo" } })
    });
    ;
    it("doesn't with partition", () => {
        expect(partition(check, dataList)).toEqual([[{ bar: "foo" }], [{ bar: "baz" }]])
        expect(partition(check, dataObj)).toEqual([{ one: { bar: "foo" } }, { two: { bar: "baz" } }]) // see below
    });
})
No overload matches this call.
  Overload 1 of 4, '(fn: (a: IFoo) => a is IFoo, list: readonly IFoo[]): [IFoo[], never[]]', gave the following error.
    Argument of type '<U>(testObj: U) => boolean' is not assignable to parameter of type '(a: IFoo) => a is IFoo'.
      Signature '(testObj: IFoo): boolean' must be a type predicate.
  Overload 2 of 4, '(fn: (a: IFoo) => boolean, list: readonly IFoo[]): [IFoo[], IFoo[]]', gave the following error.
    Argument of type '{ [id: string]: IFoo; }' is not assignable to parameter of type 'readonly IFoo[]'.
      Type '{ [id: string]: IFoo; }' is missing the following properties from type 'readonly IFoo[]': length, concat, join, slice, and 26 more.ts(2769)

See also:

Harris-Miller commented 21 hours ago

partition isn't currently typed for support of objects. We'll need to add it

Harris-Miller commented 8 hours ago

@davetapley MRs welcome if you want to give that try yourself