Skip to content

Destructuring of unknown catch variable is not an errorΒ #47383

Closed
@frigus02

Description

@frigus02

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.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestone

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions