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

Property undefined error in type definitions. #800

Closed
Axure opened this issue Oct 18, 2016 · 7 comments · Fixed by #1188
Closed

Property undefined error in type definitions. #800

Axure opened this issue Oct 18, 2016 · 7 comments · Fixed by #1188

Comments

@Axure
Copy link

Axure commented Oct 18, 2016

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
@Axure
Copy link
Author

Axure commented Oct 18, 2016

Looking at the definition:

    constructor({networkInterface, reduxRootKey, reduxRootSelector, initialState, dataIdFromObject, queryTransformer, resultTransformer, resultComparator, shouldBatch, ssrMode, ssrForceFetchDelay, mutationBehaviorReducers, batchInterval}?: {
        networkInterface?: NetworkInterface;
        reduxRootKey?: string;
        reduxRootSelector?: string | ApolloStateSelector;
        initialState?: any;
        dataIdFromObject?: IdGetter;
        queryTransformer?: QueryTransformer;
        resultTransformer?: ResultTransformer;
        resultComparator?: ResultComparator;
        shouldBatch?: boolean;
        ssrMode?: boolean;
        ssrForceFetchDelay?: number;
        mutationBehaviorReducers?: MutationBehaviorReducerMap;
        batchInterval?: number;
    });

The types aren't really compatible. We have a ? in the parameter, but no correspondence in the type. Removing that ? seems to resolve the error.

@helfer
Copy link
Contributor

helfer commented Oct 26, 2016

Which version of typescript are you using? I haven't seen this error before.

@Axure
Copy link
Author

Axure commented Nov 5, 2016

@helfer I think it results from "strickNullChecks". If it is not turned on, whether "?" exists does not matter.

tsconfig.json

It seems turned off (by default) in this repo.

@kay-is
Copy link

kay-is commented Nov 15, 2016

I can confirm this. strictNullChecks: true is the cause. The definitions probably need to be a bit "stricter" haha.

My workaround was using

const ApolloClient = require('apollo-client').default

instead of

import ApolloClient from 'apollo-client'

which skips the TypeScript definitions so I can keep strictNullChecks enabled, but now I need to write my own defs.

@helfer
Copy link
Contributor

helfer commented Nov 15, 2016

Ok, so the solution would be for us to turn strictNullChecks on in the tsc options for apollo-client? If that's all that's needed, I'd be happy to accept a PR @Axure @kay-is 🙂

@ersimont
Copy link

ersimont commented Jan 8, 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.

@lemonmade
Copy link
Contributor

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.

Pajn pushed a commit to Pajn/apollo-client that referenced this issue Jan 17, 2017
fixes apollographql#800

Enabling strictNullChecks in apollo-client itself caused a lot of errors so while it may be best solution over time, this is a quicker one that fixes the current errors.
Pajn pushed a commit to Pajn/apollo-client that referenced this issue Jan 17, 2017
fixes apollographql#800

Enabling strictNullChecks in apollo-client itself caused a lot of errors so while it may be best solution over time, this is a quicker one that fixes the current errors.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants