I am making some schema of JSON message to transfer between server & client, for serialization I created an object literal as a template such as below
type uint8 = number;
const schema1 = {
type: 'object',
fields: {
type: { type: 'uint8' },
title: { type: 'string', optional: true }
}
};
// can below automatically defined by schema1?
type schema1Type = {
type: number,
title?: string
};
const data1: schema1Type = {
type: 1,
title: 'Hello World'
};
It is alright to validate the message format by object literal schema (type alias seems cannot do this job in runtime), but for more comprehensive usage, I wish to define a type alias according to the object literal template, to guard message format in compile time, is it possible to do so? please sharing some hints for me, thank you.