Loopback-next: "Allow additional (free-form) properties?"

Created on 7 Mar 2019  路  3Comments  路  Source: strongloop/loopback-next

The lb4 model command and answer the prompts that generate the model ask whether to "Allow additional (free-form) properties?".

What are the free-form properties? I suggest to add more info in the prompt as well as in the docs for this option.

Most helpful comment

It also adds {settings: {strict: false}} to the @model() decorator:

@model({settings: {strict: false}})
export class MyModel {
  name: string;

  // This allow TypeScript to accept other properties that are not explicitly defined above
  [prop: string]: any;
}

It allows you to add properties that you haven't defined in your model class. For example, if you have a model with properties id and content, then you can add a title property when making a POST request, whereas if the no additional properties were allowed, it would reject the request with a 422.

All 3 comments

What does it today is to add the following to generated TypeScript class:

export class MyModel {
  name: string;

  // This allow TypeScript to accept other properties that are not explicitly defined above
  [prop: string]: any;
}

It also adds {settings: {strict: false}} to the @model() decorator:

@model({settings: {strict: false}})
export class MyModel {
  name: string;

  // This allow TypeScript to accept other properties that are not explicitly defined above
  [prop: string]: any;
}

It allows you to add properties that you haven't defined in your model class. For example, if you have a model with properties id and content, then you can add a title property when making a POST request, whereas if the no additional properties were allowed, it would reject the request with a 422.

Thanks for the information.

Was this page helpful?
0 / 5 - 0 ratings