One of the solutions of Exercise 12 of the TypeScript beginner's course gives me this error on Typescript playground
techemmy opened this issue · 4 comments
Hi, @techemmy! I see that is currently solution 2 to problem 12-catch-blocks.
Is that the only solution that gives you that error? I believe the error is happening because the function should be returning a value from inside the try block, which currently only throws. However, you should not be getting that error since the noImplicitReturns rule in the tsconfig.json file is commented out.
Do you have that rule enabled by chance?
Hi, @techemmy! I see that is currently solution 2 to problem 12-catch-blocks.
Is that the only solution that gives you that error? I believe the error is happening because the function should be returning a value from inside the
tryblock, which currently onlythrows. However, you should not be getting that error since thenoImplicitReturnsrule in thetsconfig.jsonfile is commented out.Do you have that rule enabled by chance?
I don't remember if I had the rule enabled, but it was the only solution giving me this error.
Hi!
Would it make sense to encourage
unknowntype introduction- first guarding against cases when
evariable
does not inherit fromErrorclass ? - so that we could narrow down the
happier pathwhen e has amessagemember variable?
P.S. The underlying exercice could have been renamed in between (since this issue has been opened in late 2022),
- from
12-catch-blocks.problem.ts - to
13-catch-blocks.problem.tsperhaps?
Hi!
Would it make sense to encourage
unknowntype introduction- first guarding against cases when
evariable
does not inherit fromErrorclass ?- so that we could narrow down the
happier pathwhen e has amessagemember variable?P.S. The underlying exercice could have been renamed in between (since this issue has been opened in late 2022),
- from
12-catch-blocks.problem.ts- to
13-catch-blocks.problem.tsperhaps?
I completely agree!
I had just started getting familiar with Typescript when I created this issue. So I didn't understand as much.
The introduction of unknown would make total sense.
