Skip to content

Type safety for functions that throw errors #32361

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

Closed
5 tasks done
bezreyhan opened this issue Jul 11, 2019 · 1 comment
Closed
5 tasks done

Type safety for functions that throw errors #32361

bezreyhan opened this issue Jul 11, 2019 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@bezreyhan
Copy link

bezreyhan commented Jul 11, 2019

Search Terms

Suggestion

Error types
Error handling

Use Cases

Knowing if a called function could throw an error. As of now, it is not obvious if a function throws an error or not.

Examples

const errorThrower = (shouldThrow: boolean): boolean =>  {
    if (shouldThrow) {
        throw new Error('Hello');
    }

    return true
}

const caller = (): boolean => {
    return errorThrower(true);
}

There should be a type error in the function caller. The type error should warn that errorThrower could throw an error and therefor the error case should be handled.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@nattthebear
Copy link

duplicate #31329 #13219

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Jul 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants