serializr icon indicating copy to clipboard operation
serializr copied to clipboard

Typing issue with update's optional modelSchema argument

Open mabeyj opened this issue 4 years ago • 1 comments

Upgrading from 1.5.1 to 2.0.3, I'm getting an error with update calls that omit the modelSchema argument. For example:

import {serializable, update} from "serializr";

class User {
  @serializable
  public name: string = "";
}

const user = new User();
update(user, {name: "Test"});
main.ts:9:1 - error TS2554: Expected 4-5 arguments, but got 2.

9 update(user, {name: "Test"})
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/serializr/lib/core/update.d.ts:16:63
    16 export default function update(modelSchema: any, target: any, json: any, callback: any, customArgs?: any): void;
                                                                     ~~~~~~~~~
    An argument for 'json' was not provided.

Seems like these overloads should use export default function instead of export function:

https://github.com/mobxjs/serializr/blob/69fed6f55bf04a2cfa07dd8cb5863af7a44be9a8/src/core/update.ts#L23-L35

Also, 2.0.3 published on npm differs from 2.0.3 tagged in this repository. The change to make callback optional is included in the 2.0.3 tag, but it's still required in 2.0.3 on npm:

main.ts:9:1 - error TS2554: Expected 4-5 arguments, but got 3.

9 update(User, user, {name: "Test"})
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/serializr/lib/core/update.d.ts:16:74
    16 export default function update(modelSchema: any, target: any, json: any, callback: any, customArgs?: any): void;
                                                                                ~~~~~~~~~~~~~
    An argument for 'callback' was not provided.

mabeyj avatar Aug 19 '20 13:08 mabeyj

Sorry for the late response.

Yeah, there was an issue with the tag. I've set up a postversion script so that hopefully doesn't happen again.

I've fixed the exports (56be5f6226f9d8646c47e8121eea2cba9428cb9d) and published a new version (2.0.5).

NaridaL avatar Dec 17 '20 00:12 NaridaL