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

Typescript connection.once inconsistency #609

Closed
lopezbertoni opened this issue Sep 20, 2019 · 4 comments · Fixed by #610
Closed

Typescript connection.once inconsistency #609

lopezbertoni opened this issue Sep 20, 2019 · 4 comments · Fixed by #610

Comments

@lopezbertoni
Copy link

Hi,

Using ably js v 1.1.18

When I want to use the Promise based API and found that in the connection.once method the compiler doesn't distinguish between the Callback based and the Promise based.

const connectedPromise = this.ablyClient.connection.once('connected'); connectedPromise.then(x => console.log('Hey'));

The error is: Property 'then' does not exist on type 'void'

The workaround is to do add a casting to any:

const connectedPromise: any = this.ablyClient.connection.once('connected'); connectedPromise.then(x => console.log('Hey'));

Looking at ably.d.ts

once(eventOrCallback: EventType | CallbackType, callback?: CallbackType): void; once(event: EventType): Promise<ResultType>;

There's really no way to tell the difference between the two methods since the callback in the first one is optional.

@SimonWoolf
Copy link
Member

Fair comment. Mind trying the typings in #610 and letting me know if that fixes your issue?

@lopezbertoni
Copy link
Author

@SimonWoolf Thanks for the quick update.
Just tried the typings in #610 and they worked like a charm.

Thanks!

@SimonWoolf
Copy link
Member

Typings fix released in 1.1.19; apologies for the delay

@lopezbertoni
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants