MakeTypes icon indicating copy to clipboard operation
MakeTypes copied to clipboard

obj is always null in error message

Open Nooka10 opened this issue 4 years ago • 0 comments

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";
    }
    .....
}

Nooka10 avatar Jul 24 '20 12:07 Nooka10