Skip to content

Commit a564953

Browse files
committed
Let typing flow better
1 parent 007ee40 commit a564953

File tree

14 files changed

+51
-41
lines changed

14 files changed

+51
-41
lines changed

.changeset/lovely-walls-drum.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'apollo-angular': patch
3+
---
4+
5+
Let typing flow better

packages/apollo-angular/headers/tests/index.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('httpHeaders', () => {
3434
Authorization: 'Bearer Foo',
3535
},
3636
},
37-
}).subscribe((result: any) => {
37+
}).subscribe(result => {
3838
expect(result.data).toEqual(data);
3939
done();
4040
});
@@ -55,7 +55,7 @@ describe('httpHeaders', () => {
5555

5656
execute(link, {
5757
query,
58-
}).subscribe((result: any) => {
58+
}).subscribe(result => {
5959
expect(result.data).toEqual(data);
6060
done();
6161
});

packages/apollo-angular/http/tests/http-batch-link.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('HttpBatchLink', () => {
4343
};
4444

4545
execute(link, op).subscribe({
46-
next: (result: any) => {
46+
next: result => {
4747
expect(result).toEqual({ data });
4848
done();
4949
},

packages/apollo-angular/http/tests/http-link.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('HttpLink', () => {
4646
};
4747

4848
execute(link, op).subscribe({
49-
next: (result: any) => expect(result).toEqual({ data }),
49+
next: result => expect(result).toEqual({ data }),
5050
error: () => {
5151
throw new Error('Should not be here');
5252
},
@@ -73,7 +73,7 @@ describe('HttpLink', () => {
7373
};
7474

7575
execute(link, op).subscribe({
76-
next: (result: any) => expect(result).toEqual({ data }),
76+
next: result => expect(result).toEqual({ data }),
7777
error: () => {
7878
throw new Error('Should not be here');
7979
},
@@ -100,7 +100,7 @@ describe('HttpLink', () => {
100100
};
101101

102102
execute(link, op).subscribe({
103-
next: (result: any) => expect(result).toEqual({ data }),
103+
next: result => expect(result).toEqual({ data }),
104104
error: () => {
105105
throw new Error('Should not be here');
106106
},
@@ -511,7 +511,7 @@ describe('HttpLink', () => {
511511

512512
test('should set response in context', (done: jest.DoneCallback) => {
513513
const afterware = new ApolloLink((op, forward) => {
514-
return forward(op).map((response: any) => {
514+
return forward(op).map(response => {
515515
const context = op.getContext();
516516

517517
expect(context.response).toBeDefined();
@@ -596,11 +596,11 @@ describe('HttpLink', () => {
596596
return m2;
597597
}),
598598
).subscribe({
599-
next(result: any) {
599+
next(result) {
600600
expect(result.data).toMatchObject(data2);
601601
done();
602602
},
603-
error(error: any) {
603+
error(error) {
604604
done.fail(error);
605605
},
606606
});

packages/apollo-angular/src/query-ref.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class QueryRef<T, V extends OperationVariables = EmptyObject> {
123123
return this.obsQuery.startPolling(pollInterval);
124124
}
125125

126-
public setOptions(opts: any) {
126+
public setOptions(opts: Partial<WatchQueryOptions<V, T>>) {
127127
return this.obsQuery.setOptions(opts);
128128
}
129129

packages/apollo-angular/testing/src/backend.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ export class ApolloTestingBackend implements ApolloTestingController {
6262
}
6363

6464
private compare(expected?: string, value?: Object | string): boolean {
65-
const prepare = (val: any) => (typeof val === 'string' ? val : JSON.stringify(val));
66-
const received = prepare(value);
65+
const received = typeof value === 'string' ? value : JSON.stringify(value);
6766

6867
return !expected || received === expected;
6968
}

packages/apollo-angular/testing/src/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export class ApolloTestingModuleCore {
4949
cache?: ApolloCache<any>,
5050
@Optional()
5151
@Inject(APOLLO_TESTING_NAMED_CACHE)
52-
namedCaches?: any, // FIX: using NamedCaches here makes ngc fail
52+
namedCaches?: NamedCaches,
5353
) {
5454
function createOptions(name: string, c?: ApolloCache<any> | null) {
5555
return {

packages/apollo-angular/testing/src/operation.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { ExecutionResult, GraphQLError } from 'graphql';
22
import { Observer } from 'rxjs';
33
import { ApolloError, FetchResult, Operation as LinkOperation } from '@apollo/client/core';
44

5-
const isApolloError = (err: any): err is ApolloError => err && err.hasOwnProperty('graphQLErrors');
5+
function isApolloError(error: unknown): error is ApolloError {
6+
return !!error && error.hasOwnProperty('graphQLErrors');
7+
}
68

79
export type Operation = LinkOperation & {
810
clientName: string;
@@ -14,17 +16,17 @@ export class TestOperation<T = { [key: string]: any }> {
1416
private readonly observer: Observer<FetchResult<T>>,
1517
) {}
1618

17-
public flush(result: ExecutionResult | ApolloError): void {
19+
public flush(result: ExecutionResult<T> | ApolloError): void {
1820
if (isApolloError(result)) {
1921
this.observer.error(result);
2022
} else {
2123
const fetchResult = result ? { ...result } : result;
22-
this.observer.next(fetchResult as any);
24+
this.observer.next(fetchResult);
2325
this.observer.complete();
2426
}
2527
}
2628

27-
public flushData(data: { [key: string]: any } | null): void {
29+
public flushData(data: T | null): void {
2830
this.flush({
2931
data,
3032
});

packages/apollo-angular/testing/tests/integration.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ describe('Integration', () => {
4242

4343
// query
4444
apollo.query<any>(op).subscribe({
45-
next: (result: any) => {
45+
next: result => {
4646
expect(result.data).toMatchObject(data);
4747
done();
4848
},
49-
error: (e: any) => {
49+
error: e => {
5050
done.fail(e);
5151
},
5252
});
@@ -75,11 +75,11 @@ describe('Integration', () => {
7575

7676
// query
7777
apollo.query<any>(op).subscribe({
78-
next: (result: any) => {
78+
next: result => {
7979
expect(result.data).toMatchObject(data);
8080
done();
8181
},
82-
error: (e: any) => {
82+
error: e => {
8383
done.fail(e);
8484
},
8585
});
@@ -108,11 +108,11 @@ describe('Integration', () => {
108108

109109
// query
110110
apollo.query<any>(op).subscribe({
111-
next: (result: any) => {
111+
next: result => {
112112
expect(result.data).toMatchObject(data);
113113
done();
114114
},
115-
error: (e: any) => {
115+
error: e => {
116116
done.fail(e);
117117
},
118118
});
@@ -144,11 +144,11 @@ describe('Integration', () => {
144144

145145
// query
146146
apollo.query<any>(op).subscribe({
147-
next: (result: any) => {
147+
next: result => {
148148
expect(result.data).toMatchObject(data);
149149
done();
150150
},
151-
error: (e: any) => {
151+
error: e => {
152152
done.fail(e);
153153
},
154154
});
@@ -204,7 +204,7 @@ describe('Integration', () => {
204204
};
205205

206206
apollo.query<any>(op).subscribe({
207-
next: (result: any) => {
207+
next: result => {
208208
expect(result.data).toMatchObject(data);
209209
done();
210210
},

packages/apollo-angular/testing/tests/module.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ describe('ApolloTestingModule', () => {
6868
};
6969

7070
apollo
71-
.query({
71+
.query<any>({
7272
query: testQuery,
7373
})
74-
.subscribe((result: any) => {
74+
.subscribe(result => {
7575
expect(result.data.heroes[0].name).toBe('Spiderman');
7676
done();
7777
});

0 commit comments

Comments
 (0)