question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Subscription Typescript Error

See original GitHub issue

Describe the bug When I try to create a subscription I get the following error Property 'subscribe' does not exist on type 'Promise<GraphQLResult<object>>'.ts(2339).

To Reproduce

  1. Create a blank amplify react app

  2. Create a subscription: ` useEffect(() => { let userSubscription: any; try { userSubscription = API.graphql( graphqlOperation(onUpdateUser, { id: userId }), ).subscribe({ next: async (value: { data: OnUpdateUserSubscription }) => { return; }, }); } catch (e) { setError(true); console.log(‘sub error’, e); }

    return () => { if (userSubscription) { userSubscription.unsubscribe(); } }; } }, [ userId, ]);`

Expected behavior Subscription should work as in the subscription example in the amplify docs.

  • OS: MacOS Catalina 10.15.3
  • Browser: Brave

Additional context I have been trying to convert my react app to ts recently and I haven’t been able to properly convert my subscriptions. I can’t find any errors specific to amplify, and the stackoverflow answers do not seem to solve this problem which makes me think this is a bug specific to amplify.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
karrettgelleycommented, Apr 20, 2020

@saevarb I appreciate the input but please only comment if you have a fix or a related concern. This post is not about DataStore, and you can read through other issues if you want to know more. This issue also doesn’t have to do with my schema or the generated types from my schema. It has to do with the types defined in the aws packages (likely @aws-amplify/api). The subscribe function is not recognized as a chainable function of API.graphql() according to typescript.

By the way, with velocity, lambda, and intentional schema design, I should think that you can do pretty much anything with your data.

1reaction
saevarbcommented, Apr 20, 2020

I would highly recommend you use the DataStore API instead of trying to use the generated types and queries. They are nearly impossible to work with in any generic way, and the DataStore stuff automatically generates proper models for all your schemas and lets you do crud operations much more easily.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular 4 : get error message in subscribe - Stack Overflow
When the id does not exist, the web api return 'BadRequest' with a message. How can I get this message ? the status...
Read more >
RxJs Error Handling: Complete Practical Guide
In this post, we will cover the following topics: The Observable contract and Error Handling; RxJs subscribe and error callbacks; The catchError ...
Read more >
How to handle and catch errors in Rxjs
In short, we learn how to pipe the data and catch the errors using catchError , to modify the return observable or use...
Read more >
Subscribe Arguments - RxJS
In short we deprecated all signatures where you specified an anonymous error or complete callback and passed an empty function to one of...
Read more >
TypeScript programming patterns - Sourcegraph docs
If you forgot to handle a Subscription returned by Rx observable.subscribe() , the ESLint rule rxjs/no-ignored-subscription will warn you. The easiest way to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found