I\'ve been trying to figure out how to create 2 mutually-incompatible number-like/integer types in TS.
For example, in the code below, height and weight are both num
So, after banging my head against the wall for several hours, I managed to come up with this:
class height extends Number {}
class weight extends Number {}
By sub-classing the Number
class, Typescript allows you to create distinct numeric types.
And then you can go and use the variables as specified above.
var a: height = 68;
var b: weight = 184;
console.log(a+b); // Should be an error.
The issue that I run into is that this also returns an error:
console.log(a+a); // Should NOT be an error.