a373626e24
To do this, I used generic-type-guard package which generates both an interface AND a valid type guard from code. With this, we are 100% sure that the messages we receive are validated at runtime! The client cannot pass us an object that is invalid! \o/
18 lines
461 B
TypeScript
18 lines
461 B
TypeScript
import * as tg from "generic-type-guard";
|
|
|
|
/*export interface PointInterface {
|
|
readonly x: number;
|
|
readonly y: number;
|
|
readonly direction: string;
|
|
readonly moving: boolean;
|
|
}*/
|
|
|
|
export const isPointInterface =
|
|
new tg.IsInterface().withProperties({
|
|
x: tg.isNumber,
|
|
y: tg.isNumber,
|
|
direction: tg.isString,
|
|
moving: tg.isBoolean
|
|
}).get();
|
|
export type PointInterface = tg.GuardedType<typeof isPointInterface>;
|