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

JSON compatibility of Option #1734

Open
florianbepunkt opened this issue Jul 20, 2022 · 1 comment
Open

JSON compatibility of Option #1734

florianbepunkt opened this issue Jul 20, 2022 · 1 comment

Comments

@florianbepunkt
Copy link

🚀 Feature request

Current Behavior

import { Json, stringify } from "fp-ts/lib/Json.js";
import * as O from "fp-ts/lib/Option.js";

type A = O.Option<string>;
const a = O.none;
const serialize = <V extends Json>(value: V) => stringify(value);
serialize(a); // <-- type signature does not match

a does not extend Json

Argument of type 'Option<never>' is not assignable to parameter of type 'Json'.
  Type 'None' is not assignable to type 'Json'.
    Type 'None' is not assignable to type 'JsonRecord'.
      Index signature for type 'string' is missing in type 'None'.

But obviously the object is json-serializable

export interface None {
  readonly _tag: 'None'
}

Desired Behavior

Suggested Solution

Who does this impact? Who is this for?

Describe alternatives you've considered

Additional context

Your environment

Software Version(s)
fp-ts
TypeScript
@viell-dev
Copy link

The interface would need to have an index signature for type string for that to be possible.
As noted by Index signature for type 'string' is missing in type 'None'.

Seems to me at least that this is better solved in userland by just adding an index signature with a predicate function or some such.

Relevant discussion: microsoft/TypeScript#15300

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

2 participants