Skip to content

Flag to type 'catch' variables as 'unknown'. #41016

Closed
@DanielRosenwasser

Description

@DanielRosenwasser

In TypeScript 4.0, we allowed users to to annotate catch variables with : unknown; however, it'd be nice if we could have that be the default.

I could imagine a flag like --useUnknownInCatchVariables to switch the default type to be unknown.

// @useUnknownInCatchVariables: true

try {
  // ...
}
catch (e) {
  e.toUpperCase(); // error
}

Alternatively, I could also imagine a much broader flag that also types parameters as unknown as well.

Metadata

Metadata

Labels

Breaking ChangeWould introduce errors in existing codeCommittedThe team has roadmapped this issueFix AvailableA PR has been opened for this issueSuggestionAn idea for TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions