News for hackers. Stuff that matters.
Re:TypeScript: Branded Types by cush on Wednesday April 24, 2024 @02:02PM (#40147653)
Yes! I've wanted this in Typescript for ages! Is it possible to brand primitives though?
Re:TypeScript: Branded Types by kristiandupont on Wednesday April 24, 2024 @02:04PM (#40147668)
Yes you can, it works just the same :-)
Re:TypeScript: Branded Types by cush on Wednesday April 24, 2024 @02:16PM (#40147780)
Sorry, with the Symbol? How does it work?
Re:TypeScript: Branded Types by maskros on Wednesday April 24, 2024 @02:43PM (#40148029)
You don't even need the symbol. If you want the simplest thing that will work:

    type Velocity = number & { BRAND: "Velocity" }
    type Distance = number & { BRAND: "Distance" }

    var x = 100 as Distance