News for hackers. Stuff that matters.
Re:Twenty five thousand dollars of funny money by chpatrick on Saturday December 03, 2022 @12:03PM (#33844955)
You can kind of do it:

  interface RobotName {
    value: string;
    type: "RobotName";
  }
Or if you don't want to make an extra wrapper around every object:

  interface RobotName {
      _phantomType: "RobotName";
  }
  
  function makeRobotName(name: string): RobotName {
      return name as any as RobotName;
  }
  
  function getRobotName(robotName: RobotName): string {
      return robotName as any as string;
  }
Presumably V8 is smart enough to inline the wrapper functions.
Re:Twenty five thousand dollars of funny money by Waterluvian on Saturday December 03, 2022 @12:34PM (#33845277)
Oh cool. So you basically lie about the runtime structure of the type, which works out fine during type checking at compilation.
Re:Twenty five thousand dollars of funny money by Waterluvian on Saturday December 03, 2022 @12:05PM (#33844979)
Discriminators are super power powerful. Love them. But they can be just so heavy for things.