Apollo-client: Usage of Object in Typescript files too restrictive?

Created on 23 Jun 2017  Β·  4Comments  Β·  Source: apollographql/apollo-client

Intended outcome:
Compilable Typescript code

Actual outcome:
TS2459:Type 'Object' has no property 'data' and no string index signature.
TS2339:Property 'data' does not exist on type 'Object'.

I am new to Typescript, so bear with me. Isn't the use of Object in many of the typescript files too restrictive?

for example
https://github.com/apollographql/apollo-client/blob/master/src/data/mutationResults.ts

import { ApolloAction } from '../actions';
export declare type MutationQueryReducer = (previousResult: Object, options: {
    mutationResult: Object;
    queryName: string | null;
    queryVariables: Object;
}) => Object;

Shouldn't it be any instead?
The TS documentation says:

Don’t ever use the types Number, String, Boolean, or Object. These types refer to non-primitive boxed objects that are almost never used appropriately in JavaScript code.
Instead of Object, use the non-primitive object type (added in TypeScript 2.2).

https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html

good-first-issue β›‘ TypeScript βœ” confirmed 🐞 bug

Most helpful comment

Hey @erkieh, I think you're right. In most cases here object should have been used, or a more appropriate { [key: string]: any}. If you make a PR I'll be happy to fast-track it! πŸ™‚

All 4 comments

I'm also having this problem. Would you guys accept a PR updating this?

Hey @erkieh, I think you're right. In most cases here object should have been used, or a more appropriate { [key: string]: any}. If you make a PR I'll be happy to fast-track it! πŸ™‚

@erkieh or @rrdelaney would you be able to PR this? I'd be happy to merge it!

PR sent to use Record<string, any> πŸ˜„

Was this page helpful?
0 / 5 - 0 ratings