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

Impossible to type #41

Closed
jack-guy opened this issue Dec 31, 2016 · 4 comments
Closed

Impossible to type #41

jack-guy opened this issue Dec 31, 2016 · 4 comments

Comments

@jack-guy
Copy link
Contributor

jack-guy commented Dec 31, 2016

I'm still slowly (but surely) working my way through and typing some core Feathers libraries. Unfortunately, I'm at an impasse with feathers-reactive. There's just no good way to statically type a function that can return both a Promise and an Observable. At best, you treat the return type as generic, but that gets messy very quickly.

While I was thinking of possible solutions, it occurred to me that the fact that this can't easily be described with a type system maybe means that it shouldn't be that way. Magically returning both a Promise and Observable with promisify is arguably not ideal from an API design standpoint.

I think one possible solution would be to use the existing method registered on the service output and have that be the exclusive thing that transform the return type, like:

service.rx().find({}).subscribe

Alternatively, the service method calls themselves could change, like

service.findReactive({})

though this is maybe a bit confusing to developers.

Any thoughts on this?

@daffl
Copy link
Member

daffl commented Dec 31, 2016

Couldn't you create a new type that extends the Observable type and has the .then(callback) and .catch(callback) methods? That's basically all it does anyway.

@jack-guy
Copy link
Contributor Author

jack-guy commented Jan 2, 2017

@daffl I've tried a few variations of that but it's complicated greatly by the fact that the type has to be modified by an entirely different declaration file. Extending the static types of modules with another imported module is tricky and likely not possible in this case without an API change.

@daffl
Copy link
Member

daffl commented Jan 2, 2017

What if you just type it as an Observable (you can always do .first().toPromise()) or does TypseScript blow up if it somehow finds methods that it didn't expect?

It's also weird to me that you can't extend an existing interface. Every static language I know of can do that.

@daffl
Copy link
Member

daffl commented Aug 28, 2017

Fixed by @j2L4e via #58 and released as v0.5.0

@daffl daffl closed this as completed Aug 28, 2017
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

No branches or pull requests

2 participants