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

TypeScript 4.4 breaks building yargs #2016

Closed
ansgarm opened this issue Aug 30, 2021 · 0 comments · Fixed by #2018
Closed

TypeScript 4.4 breaks building yargs #2016

ansgarm opened this issue Aug 30, 2021 · 0 comments · Fixed by #2018

Comments

@ansgarm
Copy link
Contributor

ansgarm commented Aug 30, 2021

Hi!

TypeScript 4.4 was released 4 days ago and introduced the following:

try {
    executeSomeThirdPartyCode();
}
catch (err) { // err: unknown

    // Error! Property 'message' does not exist on type 'unknown'.
    console.error(err.message);

    // Works! We can narrow 'err' from 'unknown' to 'Error'.
    if (err instanceof Error) {
        console.error(err.message);
    }
}

This breaks the build of yargs (there is no package-lock.json, which seems to be on purpose):

lib/argsert.ts:76:18 - error TS2571: Object is of type 'unknown'.

76     console.warn(err.stack);
                    ~~~

lib/utils/maybe-async-result.ts:22:25 - error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'Error'.

22     return errorHandler(err);
                           ~~~

Found 2 errors.
ansgarm added a commit to ansgarm/yargs that referenced this issue Aug 31, 2021
@bcoe bcoe closed this as completed in #2018 Sep 5, 2021
bcoe pushed a commit that referenced this issue Sep 5, 2021
fix: cast error types as TypeScript 4.4 infers them as unknown instead of any (#2016)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant