TypedJSON icon indicating copy to clipboard operation
TypedJSON copied to clipboard

Error: No valid 'type' option was specified for 'xxx'

Open theapache64 opened this issue 7 years ago • 1 comments

When I try to run this

import { JsonMember, JsonObject } from 'typedjson-npm';

@JsonObject
class User {
  
  @JsonMember
  first_name: string;
  
  @JsonMember
  last_name: string;
  
}

I am getting

Error: No valid 'type' option was specified for 'User.first_name'.

Any idea why it occurred ?

theapache64 avatar Jun 28 '18 11:06 theapache64

Hey, do you use reflect-metadata package? It is required for the types to be automatically guessed. If you don't want the extra package, you can manually annotate the member. With the new version available from npm (1.2.3), this is as easy as:

import { jsonMember, jsonObject } from 'typedjson';

@jsonObject
class User {
  
  @jsonMember(String)
  first_name: string;
  
  @jsonMember(String)
  last_name: string;
  
}

Neos3452 avatar Dec 09 '18 11:12 Neos3452