Skip to content

Conversation

@hearnden
Copy link
Contributor

@hearnden hearnden commented Feb 24, 2020

A Single produced by Single.error() should be assignable to any Single<T> type.

const willAlwaysError = Single.error(new Error());
const mySingle: Single<Foo> = willAlwaysError; // <-- this should always typecheck

This PR changes the default value of Single.error's type param to be empty, making it assignable to any Single<T> type.

This is the direct analogy of the default of never (same as empty) in TypeScript's Promise.reject:

reject<T = never>(reason?: any): Promise<T>;

@hearnden
Copy link
Contributor Author

hearnden commented Feb 24, 2020

I also have a branch ready for a PR on DefinitelyTyped, if this PR LGTY: DefinitelyTyped/DefinitelyTyped#42584

@hearnden hearnden changed the title makes Single.error() return a Single<never> makes Single.error() return a Single<empty> Feb 24, 2020
@stevegury
Copy link
Member

Thanks @hearnden for the improvement!
Based on my limited knowledge in Flow, this looks good to me.

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