News for hackers. Stuff that matters.
Re:Value Objects – DDD with TypeScript by skybrian on Sunday April 07, 2019 @07:30PM (#19600664)
In Go this would make sense, but having to wrap a string in an object just so that you can declare a new type for it seems like too high a price to pay.

I guess the closest thing in typescript would be a type alias, but apparently it doesn't do all that much?

Re:Value Objects – DDD with TypeScript by spankalee on Monday April 08, 2019 @12:26AM (#19602077)
You can do much better than just a type alias in TypeScript, and get specializations of primitives that type check and compile away.

    type Path = string & { _brand: never };
    
    const Path = (s: string) => validatePath(s) as Path;
    
    const p1: Path = Path('/foo/bar.js');
    const p2: Path = '/foo/bar.js';
Here, p2 has an error because a string is not assignable to a Path.
Re:Value Objects – DDD with TypeScript by skybrian on Monday April 08, 2019 @02:33AM (#19602662)
That's a neat trick! I went searching for articles about it and came up empty, though I did find other interesting uses of the "never" type.