> I mean, what if the expectation from the data that an value is a prime number? -- How are they going to encode this in their type systems? And this is just a trivial example.
In TypeScript we can define
type Prime = number
function isPrime(value: number) value is Prime {
// run sieve
}
From here, you may have e.g.
function foo(value: Prime, ...) {
}
And it will be typed checked.
function fooOrFail(v: number) {
if (isPrime(v))
foo(v)
else
throw new TypeError()
}
In TypeScript we can define
From here, you may have e.g. And it will be typed checked.