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.

Property undefined error in type definitions.

See original GitHub issue

Steps to Reproduce

Just import apollo-client.

Buggy Behavior

[0] /home/zhenghu/coding/qsc/qsc-main-react-typescript/node_modules/apollo-client/index.d.ts
[0] (47,18): error TS2459: Type '{ networkInterface?: NetworkInterface | undefined; reduxRootKey?: string | undefined; reduxRootSe...' has no property 'networkInterface' and no string index signature.
[0] /home/zhenghu/coding/qsc/qsc-main-react-typescript/node_modules/apollo-client/index.d.ts
[0] (47,36): error TS2459: Type '{ networkInterface?: NetworkInterface | undefined; reduxRootKey?: string | undefined; reduxRootSe...' has no property 'reduxRootKey' and no string index signature.
[0] /home/zhenghu/coding/qsc/qsc-main-react-typescript/node_modules/apollo-client/index.d.ts
[0] (47,50): error TS2459: Type '{ networkInterface?: NetworkInterface | undefined; reduxRootKey?: string | undefined; reduxRootSe...' has no property 'reduxRootSelector' and no string index signature.
[0] /home/zhenghu/coding/qsc/qsc-main-react-typescript/node_modules/apollo-client/index.d.ts
[0] (47,69): error TS2459: Type '{ networkInterface?: NetworkInterface | undefined; reduxRootKey?: string | undefined; reduxRootSe...' has no property 'initialState' and no string index signature.
[0] /home/zhenghu/coding/qsc/qsc-main-react-typescript/node_modules/apollo-client/index.d.ts
[0] (47,83): error TS2459: Type '{ networkInterface?: NetworkInterface | undefined; reduxRootKey?: string | undefined; reduxRootSe...' has no property 'dataIdFromObject' and no string index signature.
[0] /home/zhenghu/coding/qsc/qsc-main-react-typescript/node_modules/apollo-client/index.d.ts
[0] (47,101): error TS2459: Type '{ networkInterface?: NetworkInterface | undefined; reduxRootKey?: string | undefined; reduxRootSe...' has no property 'queryTransformer' and no string index signature.
[0] /home/zhenghu/coding/qsc/qsc-main-react-typescript/node_modules/apollo-client/index.d.ts
[0] (47,119): error TS2459: Type '{ networkInterface?: NetworkInterface | undefined; reduxRootKey?: string | undefined; reduxRootSe...' has no property 'resultTransformer' and no string index signature.
[0] /home/zhenghu/coding/qsc/qsc-main-react-typescript/node_modules/apollo-client/index.d.ts
[0] (47,138): error TS2459: Type '{ networkInterface?: NetworkInterface | undefined; reduxRootKey?: string | undefined; reduxRootSe...' has no property 'resultComparator' and no string index signature.
[0] /home/zhenghu/coding/qsc/qsc-main-react-typescript/node_modules/apollo-client/index.d.ts
[0] (47,156): error TS2459: Type '{ networkInterface?: NetworkInterface | undefined; reduxRootKey?: string | undefined; reduxRootSe...' has no property 'shouldBatch' and no string index signature.
[0] /home/zhenghu/coding/qsc/qsc-main-react-typescript/node_modules/apollo-client/index.d.ts
[0] (47,169): error TS2459: Type '{ networkInterface?: NetworkInterface | undefined; reduxRootKey?: string | undefined; reduxRootSe...' has no property 'ssrMode' and no string index signature.
[0] /home/zhenghu/coding/qsc/qsc-main-react-typescript/node_modules/apollo-client/index.d.ts
[0] (47,178): error TS2459: Type '{ networkInterface?: NetworkInterface | undefined; reduxRootKey?: string | undefined; reduxRootSe...' has no property 'ssrForceFetchDelay' and no string index signature.
[0] /home/zhenghu/coding/qsc/qsc-main-react-typescript/node_modules/apollo-client/index.d.ts
[0] (47,198): error TS2459: Type '{ networkInterface?: NetworkInterface | undefined; reduxRootKey?: string | undefined; reduxRootSe...' has no property 'mutationBehaviorReducers' and no string index signature.
[0] /home/zhenghu/coding/qsc/qsc-main-react-typescript/node_modules/apollo-client/index.d.ts
[0] (47,224): error TS2459: Type '{ networkInterface?: NetworkInterface | undefined; reduxRootKey?: string | undefined; reduxRootSe...' has no property 'batchInterval' and no string index signature.

Expected Behavior

No error.

Version

  • apollo-client@0.4.21
  • react-apollo@0.5.11

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lemonmadecommented, Jan 16, 2017

This is also biting me, also using strictNullChecks. I’m just casting to get this to work without copying any definitions around, but would be great to get it resolved in the shipped definitions.

0reactions
ersimontcommented, Jan 16, 2017

I fixed this by manually editing the .d.ts file to remove the first ? from the constructor declaration (at the end of the second line below) to eliminates the errors, and adding a second constructor declaration for the case when nothing is passed in:

    constructor();
    constructor({networkInterface, reduxRootKey, reduxRootSelector, initialState, dataIdFromObject, resultComparator, ssrMode, ssrForceFetchDelay, mutationBehaviorReducers, addTypename, resultTransformer, customResolvers, connectToDevTools, queryDeduplication}: {
        networkInterface?: NetworkInterface;
        reduxRootKey?: string;
        reduxRootSelector?: string | ApolloStateSelector;
        initialState?: any;
        dataIdFromObject?: IdGetter;
        resultTransformer?: ResultTransformer;
        resultComparator?: ResultComparator;
        ssrMode?: boolean;
        ssrForceFetchDelay?: number;
        mutationBehaviorReducers?: MutationBehaviorReducerMap;
        addTypename?: boolean;
        customResolvers?: CustomResolverMap;
        connectToDevTools?: boolean;
        queryDeduplication?: boolean;
    });

I was going to submit a PR for this, but the .d.ts file does not appear to be in the repo? I guess it is generated by some magic that I have not yet learned.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError: Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
Uncaught TypeError: Cannot read property of undefined In
In basic terms, undefined means that a variable has been declared but has not yet been assigned a value. This particular error is...
Read more >
Why does TypeScript not check for undefined when looking up ...
When looking up properties from such an object, they are returned as number s, as is expected. let key = 'pi'; let pi...
Read more >
How to Deal with Optional Things and "Undefined" in TypeScript
Working with JavaScript means working with undefined . It's a standard way to say, “This thing you asked for doesn't exist.”.
Read more >
How to Avoid the Infamous "Cannot read properties of ... - Bitovi
That error message is telling you the function is returning undefined implicitly, but its return type does not include undefined in it. Awesome!...
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