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.

Type error with typescript using example

See original GitHub issue

I’m following the example to set up next-with-apollo and am trying to do so using typescript instead of regular JavaScript. However, I’m getting the follow error when I do so:

[ts]
Argument of type 'typeof MyApp' is not assignable to parameter of type 'typeof App'.
  Types of parameters 'props' and 'props' are incompatible.
    Type 'TProps & AppComponentProps' is not assignable to type 'Props & AppComponentProps'.
      Type 'TProps & AppComponentProps' is not assignable to type 'Props'.
        Property 'apollo' is missing in type 'AppComponentProps'.
class MyApp

Here is my _app.tsx

import App, { Container } from 'next/app';
import ApolloClient from 'apollo-boost';
import { ApolloProvider } from 'react-apollo';
import withApollo from '../lib/withApollo';

interface Props {
  apollo: ApolloClient<any>;
}

class MyApp extends App<Props> {
  render() {
    const { Component, pageProps, apollo } = this.props;

    return (
      <Container>
        <ApolloProvider client={apollo}>
          <Component {...pageProps} />
        </ApolloProvider>
      </Container>
    );
  }
}

export default withApollo(MyApp);

The withApollo.ts didn’t change from the example in the README.

Did I miss some simple here? I assumed given that this was written in TypeScript that it should work pretty simply.

Thanks!!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
lfadescommented, Apr 17, 2019

@hisea Can you add the apollo prop like here ?

interface Props {
  apollo: ApolloClient<any>;
}

class MyApp extends App<Props> {
0reactions
hiseacommented, Apr 17, 2019

Thank you, it worked well.

sorry for my novice typescript question.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Understanding Errors - TypeScript
Whenever TypeScript finds an error, it tries to explain what went wrong in as much detail as possible. Because its type system is...
Read more >
Get a catch block error message with TypeScript - Kent C. Dodds
TypeScript forces you to acknowledge you can't know what was thrown making getting the error message a pain. Here's how you can manage...
Read more >
Type-Safe Error Handling In TypeScript - DEV Community ‍ ‍
In this post, I introduce the concept of a Result type, which eliminates the need for throwing exceptions, and reduces risk of runtime ......
Read more >
Improving TypeScript error handling with exhaustive type ...
In this article, we'll cover a few of the most common approaches for error handling in TypeScript (TS). We'll talk about most common...
Read more >
Exception Handling - TypeScript Deep Dive - Gitbook
Creates an instance representing an error that occurs when a variable or parameter is not of a valid type.
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