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

obj is always null in error message #19

Open
Nooka10 opened this issue Jul 24, 2020 · 0 comments
Open

obj is always null in error message #19

Nooka10 opened this issue Jul 24, 2020 · 0 comments
Labels

Comments

@Nooka10
Copy link

Nooka10 commented Jul 24, 2020

Hi,

When you use MakeType from your website, the generated Typescript proxies output contain a create function that never initialize the obj object.
So in the error message, the full object is always null...

Error: TypeError: Expected number at root.id but found:
undefined

Full object:
null

That's because there is a default value for the field parameter, so the if(!field) test is always false...

public static Create(d: any, field: string = 'root'): ExampleProxy {
    if (!field) {
      obj = d;
      field = "root";
    }
    .....
}

You should remove the default value and make the parameter optional:

public static Create(d: any, field?: string): ExampleProxy {
    if (!field) {
      obj = d;
      field = "root";
    }
    .....
}
@jvilk jvilk added the bug label Jul 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants