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

Support unknown on catch clauses #59

Closed
danielnixon opened this issue Jul 21, 2020 · 2 comments
Closed

Support unknown on catch clauses #59

danielnixon opened this issue Jul 21, 2020 · 2 comments
Labels
enhancement New feature or request fixed and released

Comments

@danielnixon
Copy link

In TypeScript 4.0 we can finally treat caught exceptions as unknown instead of any.

From https://devblogs.microsoft.com/typescript/announcing-typescript-4-0-beta/#unknown-on-catch:

try {
    // ...
}
catch (e: unknown) {
    // error!
    // Property 'toUpperCase' does not exist on type 'unknown'.
    console.log(e.toUpperCase());

    if (typeof e === "string") {
        // works!
        // We've narrowed 'e' down to the type 'string'.
        console.log(e.toUpperCase());
    }
}

It would be good to consider these typed/safe (even when --ignore-catch is false).

See also

@plantain-00
Copy link
Owner

plantain-00 commented Jul 21, 2020

v2.10.0-beta.0 support typescript 4 beta now.
I forgot 2 || 3 || 4 cannot resolve to 4.0.0-beta, I will wait until typescript 4 released

@plantain-00
Copy link
Owner

released in v2.10.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed and released
Projects
None yet
Development

No branches or pull requests

2 participants