// Declared as `number`. May throw at any point.
function parseAge(input: string): number {
const n = parseInt(input)
if (isNaN(n)) throw new Error("Not a number")
if (n < 0) throw new Error("Negative age")
const age: number = parseAge("banana") // compiles. blows up.
TypeScript has no throws clause. The return type carries no information about failure, and callers receive no warning.
Every throwing function widens the runtime surface the type system pretends does not exist.
Notice. The compiler accepted const age: number = parseAge("banana")
without a warning. The runtime throws. The signature and the behaviour
disagree, and the compiler has no way to tell you.
Your turn: run the tests and confirm both throws fire from a function declared : number. You should see two failures inside the success path.