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
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> π
Most helpful comment
Hey @erkieh, I think you're right. In most cases here
objectshould have been used, or a more appropriate{ [key: string]: any}. If you make a PR I'll be happy to fast-track it! π