total-typescript/beginners-typescript-tutorial

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

The 3rd solution gives me the error on the TypeScript playground as well.

Screenshot 2022-10-31 at 22 19 13

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 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?

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

  • unknown type introduction
  • first guarding against cases when e variable
    does not inherit from Error class ?
  • so that we could narrow down the happier path when e has a message member 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.ts perhaps?

Hi!

Would it make sense to encourage

  • unknown type introduction
  • first guarding against cases when e variable
    does not inherit from Error class ?
  • so that we could narrow down the happier path when e has a message member 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.ts perhaps?

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.