Skip to content

Type error when traversing Record with fixed keys #36

@fabianpage

Description

@fabianpage

🐛 Bug report

Current Behavior

Hi
Thanks for this awesome library! I think the type of the Path to traverse a Record with fixed Keys is wrong.

  type A = {
    b: Record<string, C>;
  };

  type AWithFixedKeys = {
    b: Record<"c", C>;
  };

  type C = {
    d: string;
  };

  const anA: A = { b: { someKey: { d: "test" } } };
  const anAWithKeys: AWithFixedKeys = { b: { c: { d: "test" } } };

  const setA = pipe(anA, set("b.{}>.d", "someValue"));
  const setAKeys = pipe(anAWithKeys, set("b.{}>.d", "someOtherValue"));

  const getA = pipe(setA, get("b.{}>.d"));
  const getAKeys = pipe(setAKeys, get("b.{}>.d"));

  console.log({ getA }, { getAKeys });

The return value is okay:

 { getA: [ 'someValue' ] } { getAKeys: [ 'someOtherValue' ] }

But on the 2 paths i get the following error:

src/entries.ts:117:42 - error TS2345: Argument of type '"b.{}>.d"' is not assignable to parameter of type '"" | "b" | "b.c" | "b.c.d"'.

117   const setAKeys = pipe(anAWithKeys, set("b.{}>.d", "someOtherValue"));
                                             ~~~~~~~~~

src/entries.ts:120:39 - error TS2345: Argument of type '"b.{}>.d"' is not assignable to parameter of type '"" | "b" | "b.c" | "b.c.d"'.

120   const getAKeys = pipe(setAKeys, get("b.{}>.d"));
                                          ~~~~~~~~~

Expected behavior

Not have an type error :)

Your environment

Which versions of fp-ts are affected by this issue? Did this work in previous versions of fp-ts?

Software Version(s)
spectacles-ts 1.0.7
fp-ts 2.12.11
TypeScript 4.6.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions