3 ms·
The simplest way I know of to make a discriminated number type in TypeScript is: declare const isRobotID: unique symbol; type RobotID = number & { [isR
by Jasper_ 4y ago
The simplest way I know of to make a discriminated number type in TypeScript is:
declare const isRobotID: unique symbol;
type RobotID = number & { [isRobotID]: true };
and now you can cast a number to a RobotID and back.