Skip to content

$push and ReadonlyArray<T> does not play nice #154

@m-rutter

Description

@m-rutter

I am having issues with $push and ReadonlyArray types, which is very common in graphql codegen generated interfaces.

Minimal Example

interface Thing {
  bar: {
    foo: ReadonlyArray<{ baz: number }>;
  };
}

declare const a: Thing;
declare const b: Thing;

update(a, { bar: { foo: { $push: b.bar.foo } } });

returns this type error:

Type 'readonly { baz: number; }[]' is not assignable to type 'Spec<{ baz: number; }, never>'.
  Type 'readonly { baz: number; }[]' is not assignable to type '(v: { baz: number; }) => { baz: number; }'.
    Type 'readonly { baz: number; }[]' provides no match for the signature '(v: { baz: number; }): { baz: number; }'.ts(2322)

Workaround

Use $set instead

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