Reproduces a linter issue in the createTestClient
function reported by typescript-eslint with the type-aware rules.
npm install
npm run lint
The following linter errors, related to the createTestClient function, are reported:
/directory/reproduce-create-test-client-typing-issue/src/index.test.ts
9:11 error Avoid referencing unbound methods which may cause unintentional scoping of `this`.
If your function does not access `this`, you can annotate it with `this: void`, or consider using an arrow function instead @typescript-eslint/unbound-method
9:11 error Avoid referencing unbound methods which may cause unintentional scoping of `this`.
If your function does not access `this`, you can annotate it with `this: void`, or consider using an arrow function instead @typescript-eslint/unbound-method
No linter errors occur.
- Edit the
node_modules/apollo-server-testing/dist/createTestClient.d.ts
file. Replace this type definition:
export interface ApolloServerTestClient {
query<TData = any, TVariables = Record<string, any>>(query: Query<TVariables>): Promise<GraphQLResponse<TData>>;
mutate<TData = any, TVariables = Record<string, any>>(mutation: Mutation<TVariables>): Promise<GraphQLResponse<TData>>;
}
with this type definition:
export interface ApolloServerTestClient {
query: <TData = any, TVariables = Record<string, any>>(query: Query<TVariables>) => Promise<GraphQLResponse<TData>>;
mutate: <TData = any, TVariables = Record<string, any>>(mutation: Mutation<TVariables>) => Promise<GraphQLResponse<TData>>;
}
- Run
npm run lint
again in the repository root directory. It should no longer cause linter errors.