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

use more exact return type in Notification#do #5031

Closed

Conversation

jokester
Copy link

@jokester jokester commented Sep 23, 2019

Description:

This prevents a return type of any when the type can be inferred from callback types.


// Before: return type is always `any`

// ============

// After:

// when all 3 callbacks are specified: return type becomes (union of their return types)
const a = notification.do(
  _ => 'str',
  _ => 123,
  _ => ({a: 1})
);  // => a: string | number | {a: number}

// when not all of callbacks are specified:
// return type becomes (undefined | union of specified return types)
const b = notification.do(
  _ => 'str'
); // => b: string | undefined

Related issue (if exists):

@jokester jokester force-pushed the refine-notation-do-return-type branch from 95e0d1c to 8192532 Compare September 23, 2019 03:10
@benlesh
Copy link
Member

benlesh commented Jun 9, 2020

Closing this in favor of #5478

Thank you for your effort, @jokester ... it's helpful and it drew our attention to the issue.

@benlesh benlesh closed this Jun 9, 2020
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