One of the challenges I face is dealing with a loopback model that is often represented in raw JSON format. For example:
@model()
class SomeModel extends Entity {
@property({ type: 'string' })
id?: string;
}
In its raw JSON form, it would look like this:
interface IRawSomeModel {id?: string}
I'm wondering if there is a way to generate the IRawSomeModel
interface programmatically?
One approach I've considered is combining the two interfaces, but it involves duplicating everything:
export interface IRawSomeModel {id?: string}
@model()
export class SomeModel extends Entity implements IRawSomeModel {
@property({ type: 'string' })
id?: string;
}
Ultimately, I am seeking a syntax similar to
RawObjectFormOfModel<SomeModel>
.
The goal is to write code like this without any errors:
const obj: RawObjectFormOfModel<SomeModel> = {}; // no error about missing class functions
obj.id = "test"
What is the most efficient method to obtain a raw object type representation of models?