Intermediate
A Generic Result Type
safeDivide returns a Result that is either a success with a number or a failure with a text. The type is written for numbers only, so it can't be reused.
Make Result generic: Result<T, E> with E defaulting to string. Then safeDivide returns Result<number>. The checks use Result with other value and error types.
What Check tests
- Your code has no type errors
- The console prints
5anddivide by zero Result<number>accepts a successResult<string, Error>accepts an Error failure- A text where a number is promised is rejected
- The default error type is
string
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Runs in your browser. Your code is saved here.
Press Run to see the page.
Console
Nothing printed yet.