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

Typing issue with update's optional modelSchema argument #139

Open
mabeyj opened this issue Aug 19, 2020 · 1 comment
Open

Typing issue with update's optional modelSchema argument #139

mabeyj opened this issue Aug 19, 2020 · 1 comment

Comments

@mabeyj
Copy link

mabeyj commented Aug 19, 2020

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:

export function update<T>(
modelschema: ClazzOrModelSchema<T>,
instance: T,
json: any,
callback?: (err: any, result: T) => void,
customArgs?: any
): void
export function update<T>(
instance: T,
json: any,
callback?: (err: any, result: T) => void,
customArgs?: any
): void

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.
@NaridaL
Copy link
Collaborator

NaridaL commented Dec 17, 2020

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 (56be5f6) and published a new version (2.0.5).

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