Skip to content

JSON.stringify does not accept non-readonly object #5

Closed
@kku39

Description

@kku39

Version

2.0.0-beta

Code

interface Param {
  id: string;
  value: number;
}
export function foo(param: Param, readonlyParam: Readonly<Param>) {
  JSON.stringify(param); // error
  JSON.stringify(readonlyParam);
}

Actual Behavior

Compile error: ts(2769) [6, 18]

No overload matches this call.
  Overload 1 of 2, '(value: ReadonlyJSONValue, replacer?: ((this: ReadonlyJSONValue, key: string, value: ReadonlyJSONValue) => any) | undefined, space?: string | ... 1 more ... | undefined): string', gave the following error.
    Argument of type 'Param' is not assignable to parameter of type 'ReadonlyJSONValue'.
      Type 'Param' is not assignable to type '{ readonly [x: string]: ReadonlyJSONValue | undefined; }'.
        Index signature for type 'string' is missing in type 'Param'.
  Overload 2 of 2, '(value: ReadonlyJSONValue, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string', gave the following error.
    Argument of type 'Param' is not assignable to parameter of type 'ReadonlyJSONValue'.

Expected Behavior

No error

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions