Skip to content

useUnknownInCatchVariables would do much better to require ": unknown" rather than magically injecting itΒ #59100

Open

Description

πŸ”Ž Search Terms

useUnknownInCatchVariables

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about useUnknownInCatchVariables

⏯ Playground Link

No response

πŸ’» Code

No response

πŸ™ Actual behavior

With useUnknownInCatchVariables :unknonw is magically injected after err (in catch (err))

try {
  console.log("in try")
}
catch (err) {
  console.log("in catch")
  console.log(err.message)
}

This results in a mysterious failure like so (from deno i.e. swc):

error: TS18046 [ERROR]: 'err' is of type 'unknown'.
    console.log(err.message)

The design of this option is very wrong, it's not worth the tiny saving of not having to type :unknown give how mysterious the above error is for a user who isn't aware of this option. It should have been designed to require this declaration rather than injecting it.

I realize this option can't be fixed at this point and it's probably not worth introducing a similar one with the better behavior. Perhaps as an alternative swc (and maybe other compilers) could be fixed to give an error that at least mentions useUnknownInCatchVariables.

πŸ™‚ Expected behavior

Something less mysterious :)

Additional information about the issue

None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Domain: Error MessagesThe issue relates to error messagingExperience EnhancementNoncontroversial enhancementsNeeds ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions