Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destructuring of unknown catch variable is not an error #47383

Closed
frigus02 opened this issue Jan 11, 2022 · 1 comment Β· Fixed by #52240
Closed

Destructuring of unknown catch variable is not an error #47383

frigus02 opened this issue Jan 11, 2022 · 1 comment Β· Fixed by #52240
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@frigus02
Copy link
Contributor

Bug Report

πŸ”Ž Search Terms

catch, destructure, destructuring, useUnknownInCatchVariables

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried: v4.0.5, v4.5.4

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

let a: unknown;
let {foo} = a;
//   ^^^ Property 'foo' does not exist on type 'unknown'.(2339)

function bar({foo}: unknown) {}
//            ^^^ Property 'foo' does not exist on type 'unknown'.(2339)

try {
} catch ({foo}: unknown) {
  // foo is type any
  // with useUnknownInCatchVariables foo is type unknown
}

πŸ™ Actual behavior

Destructuring unknown is an error, but destructuring a catch variable, which is of type unknown is not an error.

πŸ™‚ Expected behavior

I would expect destructuring of a catch variable of type unknown to produce an error.

@lvelden
Copy link

lvelden commented Jan 11, 2022

If the type annotation is any, the property type seems also wrong with --useUnknownInCatchVariables:

try {
} catch ({foo}: any) {
  // foo is type any
  // with useUnknownInCatchVariables foo is type unknown
}

[Playground link]

Expected behavior

Property type of destructured any type is also any.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
5 participants