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

Better TypeScript typing for throws assertions #1956

Merged
merged 6 commits into from
Oct 14, 2018

Conversation

novemberborn
Copy link
Member

@novemberborn novemberborn commented Oct 13, 2018

Fixes #1893.

I might do Flow tomorrow if I have the time.


test('throws', t => {
const err1: Error = t.throws(() => {});
// t.is(err1.foo, 'foo');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a type exception. I think maybe there's a way to indicate that to tsc?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the // @ts-ignore comment to ignore the below line.


test('throws', t => {
const err = t.throws<CustomError>(myFunc);
t.is(err.parent.name, 'TypeError');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also include the contents of myFunc somewhere as it's not that clear where TypeError comes from.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@novemberborn
Copy link
Member Author

I've added the Flow typing too.

@novemberborn novemberborn merged commit 7be3f99 into master Oct 14, 2018
@novemberborn novemberborn deleted the better-throws-typing branch October 14, 2018 14:26
novemberborn added a commit that referenced this pull request Oct 28, 2018
sindresorhus pushed a commit that referenced this pull request Oct 29, 2018
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 this pull request may close these issues.

2 participants