Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evolve typings #447

Open
icaroponce opened this issue Jun 21, 2020 · 0 comments
Open

Evolve typings #447

icaroponce opened this issue Jun 21, 2020 · 0 comments

Comments

@icaroponce
Copy link

Hi there,

I'm having issues trying to type the evolve method when the properties' type changes. E.g. string changes to number as seen below:

const t  = {
  price: v => (v ? parseFloat(v) : null),
  track: v => (v ? 'ON' : 'OFF'),
};

type T = {
  price: string | null;
  track: boolean;
};

const i: T = {
  price: '111',
  track: true,
};

const e = evolve(t, i);

Trying to type the transformations object with:

const t: {
  price: Morphism<string | null, number | null>;
  track: Morphism<boolean, 'ON' | 'OFF'>;
} = {...}

gives this error back

[tsserver 2769] [E] No overload matches this call.
  Overload 1 of 6, '(_transformations: Placeholder, object: T): evolve_01<unknown, T>', gave the following error.
    Argument of type '{ price: Morphism<string | null, number | null>; track: Morphism<boolean, "ON" | "OFF">; }' is not assignable to parameter of type 'Placeholder'.
      Property '"@@functional/placeholder"' is missing in type '{ price: Morphism<string | null, number | null>; track: Morphism<boolean, "ON" | "OFF">; }' but required in type 'Placeholder'.
  Overload 2 of 6, '(transformations: Evolver<{ price: number | null; track: "ON" | "OFF"; }>, object: { price: number | null; track: "ON" | "OFF"; }): { price: number | null; track: "ON" | "OFF"; }', gave the following error.
    Argument of type '{ price: Morphism<string | null, number | null>; track: Morphism<boolean, "ON" | "OFF">; }' is not assignable to parameter of type 'Evolver<{ price: number | null; track: "ON" | "OFF"; }>'.
      Type '{ price: Morphism<string | null, number | null>; track: Morphism<boolean, "ON" | "OFF">; }' is not assignable to type '{ price?: number | Morphism<number | null, number | null> | null | undefined; track?: "ON" | "OFF" | Morphism<"ON" | "OFF", "ON" | "OFF"> | undefined; }'.
        Types of property 'price' are incompatible.
          Type 'Morphism<string | null, number | null>' is not assignable to type 'number | Morphism<number | null, number | null> | null | undefined'.
            Type 'Morphism<string | null, number | null>' is not assignable to type 'Morphism<number | null, number | null>'.
              Type 'number | null' is not assignable to type 'string | null'.
                Type 'number' is not assignable to type 'string | null'.

Any ideas about what is going wrong here?

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant