rxjs icon indicating copy to clipboard operation
rxjs copied to clipboard

fix: subscribe and tap type overloads

Open vthinkxie opened this issue 3 years ago • 10 comments

close #6717

Description:

fix type error caused by observable subscribe function overloads

Related issue (if exists): #6717

vthinkxie avatar Dec 13 '21 11:12 vthinkxie

I disagree with the suggested change on this PR. As a developer I much rather seeing 2 different overloads on my IDE, than conflating the already existing ones into 1 overload. Also, I don't think that #6717 is a real issue.

josepot avatar Dec 13 '21 11:12 josepot

I disagree with the suggested change on this PR. As a developer I much rather seeing 2 different overloads on my IDE, than conflating the already existing ones into 1 overload. Also, I don't think that #6717 is a real issue.

Hi @josepot , maybe we can discuss the issue separately.

  • Should the next param here be optional? https://github.com/ReactiveX/rxjs/blob/081ca2ba7290aa3084c1477a6d4bcc573bf478f6/src/internal/Observable.ts#L78 I think this param should be optional, since the implements of the overload support optional https://github.com/ReactiveX/rxjs/blob/081ca2ba7290aa3084c1477a6d4bcc573bf478f6/src/internal/Observable.ts#L214

  • Are the overloads here good overloads? According to Writing Good Overloads in typescript handbook, with the same argument count and same return type, I don't think 2 different overloads here is good overloads. Always prefer parameters with union types instead of overloads when possible.

2021-12-13 下午8 51 12

vthinkxie avatar Dec 13 '21 12:12 vthinkxie

This looks correct to me. And I think we'll need a similar change made to the tap signatures, too.

cartant avatar Dec 13 '21 21:12 cartant

This looks correct to me. And I think we'll need a similar change made to the tap signatures, too.

Hi @cartant , thanks for your comments. Should I make a change to tap in this PR or submit another PR?

vthinkxie avatar Dec 15 '21 02:12 vthinkxie

It's so closely related that I'm fine with it being in this PR in an additional commit. Thanks.

cartant avatar Dec 15 '21 02:12 cartant

It's so closely related that I'm fine with it being in this PR in an additional commit. Thanks.

@cartant done

vthinkxie avatar Dec 15 '21 03:12 vthinkxie

I can see the spirit of this, I guess the only other thing to consider would be the documentation side of things. Both on the site and in our IDEs. Each manner of calling this has slightly different implications that should be communicated to the user. I'm sure that the single overload is probably better for TS compilation time, but what is better for the developer experience? ('m not saying I know, I'm just presenting the question: "Can we serve people better with separately documented overloads here?"

benlesh avatar Jan 07 '22 16:01 benlesh

I can see the spirit of this, I guess the only other thing to consider would be the documentation side of things. Both on the site and in our IDEs. Each manner of calling this has slightly different implications that should be communicated to the user. I'm sure that the single overload is probably better for TS compilation time, but what is better for the developer experience? ('m not saying I know, I'm just presenting the question: "Can we serve people better with separately documented overloads here?"

maybe we can add more description in the comment of source code instead of the typescript overloads?

vthinkxie avatar Jan 12 '22 07:01 vthinkxie

Core Team: Approval.

benlesh avatar Jan 12 '22 21:01 benlesh

Hi @benlesh any chance of merging this PR recently?

vthinkxie avatar Mar 23 '22 08:03 vthinkxie

Thank you, @vthinkxie!

benlesh avatar Dec 03 '22 19:12 benlesh