Skip to content

Destructuring of unknown catch variable is not an error #47383

Closed

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.

Activity

  1. lvelden commented on Jan 11, 2022

    @lvelden

    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.

  2. added
    Fix Available
    on Jan 14, 2022
  3. added
    Rescheduled
    on May 13, 2022
  4. removed
    Fix Available
    on Oct 25, 2022
  5. added
    Fix Available
    on Jan 14, 2023
  6. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugFix AvailableRescheduled

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions