plantain-00 / type-coverage

A CLI tool to check type coverage for typescript code
MIT License
1.25k stars 44 forks source link

Support `unknown` on catch clauses #59

Closed danielnixon closed 4 years ago

danielnixon commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

released in v2.10.0