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

fix: Make WebSocketSubjectConfig a generic type #2755

Conversation

fangpenlin
Copy link

Description:

Fix typescript type issue for websocket #2754, make WebSocketSubjectConfig a generic type, so that it will respect the type T from websocket.

In this way, the type can be inferred correctly from the resultSelector's result type, you can write something like

const myWebSocket = webSocket({
  url: 'ws://localhost:8080',
  resultSelector: (e: MessageEvent) => e.data + '!'
})

the myWebSocket will automatically inferred as WebSocketSubject<string>

@fangpenlin
Copy link
Author

Hmmm, not sure what about default type

const myWebSocket = webSocket({
  url: 'ws://localhost:8080'
})

it seems by default the T will get inferred to be {} strangely in this case. Maybe we should make the T default to any, as the default resultSelector is implementing as a JSON parser?

@kwonoj
Copy link
Member

kwonoj commented Jul 18, 2017

I guess this should target next branch with default generic features in TS compiler.

@rxjs-bot
Copy link

Messages
📖

CJS: 3174.1KB, global: 588.9KB (gzipped: 108.6KB), min: 138.0KB (gzipped: 29.1KB)

Generated by 🚫 dangerJS

@coveralls
Copy link

coveralls commented Jul 18, 2017

Coverage Status

Coverage remained the same at 97.734% when pulling faf0d72 on fangpenlin:fang/bugfix2754/inferening-correct-type-for-websocket-result-selector into 491970f on ReactiveX:master.

@fangpenlin
Copy link
Author

@kwonoj

sorry, maybe we should hold on a little bit on this PR, just tried, even with default generic type

export class WebSocketSubject<T = any> extends AnonymousSubject<T> {

Somehow we are still getting {} as the inferred type if resultSelector is not given :/

I am not sure how TypeScript works in terms of getting {} out of undefined resultSelector, that's really odd behavior

@kwonoj kwonoj added the TS Issues and PRs related purely to TypeScript issues label Jul 18, 2017
@benlesh
Copy link
Member

benlesh commented Mar 30, 2018

This is done in master.

@benlesh benlesh closed this Mar 30, 2018
@lock
Copy link

lock bot commented Jun 5, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
TS Issues and PRs related purely to TypeScript issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants