Skip to content

Commit

Permalink
Fix TypeScript errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarsolorzano committed Jun 7, 2017
1 parent e12a7df commit b3c3efa
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 136 deletions.
2 changes: 1 addition & 1 deletion src/data/storeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export interface JsonValue {

export type ListValue = Array<null | IdValue>;

export type StoreValue = number | string | string[] | IdValue | ListValue | JsonValue | null | undefined | void;
export type StoreValue = number | string | string[] | IdValue | ListValue | JsonValue | null | undefined | void | Object;

export function isIdValue(idObject: StoreValue): idObject is IdValue {
return (
Expand Down
44 changes: 22 additions & 22 deletions test/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ describe('ApolloClient', () => {
},
});

assert.deepEqual(client.readQuery({ query: gql`{ a }` }), { a: 1 });
assert.deepEqual(client.readQuery({ query: gql`{ b c }` }), { b: 2, c: 3 });
assert.deepEqual(client.readQuery({ query: gql`{ a b c }` }), { a: 1, b: 2, c: 3 });
assert.deepEqual<{}>(client.readQuery({ query: gql`{ a }` }), { a: 1 });
assert.deepEqual<{}>(client.readQuery({ query: gql`{ b c }` }), { b: 2, c: 3 });
assert.deepEqual<{}>(client.readQuery({ query: gql`{ a b c }` }), { a: 1, b: 2, c: 3 });
});

it('will read some deeply nested data from the store', () => {
Expand Down Expand Up @@ -64,15 +64,15 @@ describe('ApolloClient', () => {
},
});

assert.deepEqual(
assert.deepEqual<{}>(
client.readQuery({ query: gql`{ a d { e } }` }),
{ a: 1, d: { e: 4, __typename: 'Foo' } },
);
assert.deepEqual(
assert.deepEqual<{}>(
client.readQuery({ query: gql`{ a d { e h { i } } }` }),
{ a: 1, d: { __typename: 'Foo', e: 4, h: { i: 7, __typename: 'Bar' } } },
);
assert.deepEqual(
assert.deepEqual<{}>(
client.readQuery({ query: gql`{ a b c d { e f g h { i j k } } }` }),
{ a: 1, b: 2, c: 3, d: { __typename: 'Foo', e: 4, f: 5, g: 6, h: { __typename: 'Bar', i: 7, j: 8, k: 9 } } },
);
Expand All @@ -92,7 +92,7 @@ describe('ApolloClient', () => {
},
});

assert.deepEqual(client.readQuery({
assert.deepEqual<{}>(client.readQuery({
query: gql`query ($literal: Boolean, $value: Int) {
a: field(literal: true, value: 42)
b: field(literal: $literal, value: $value)
Expand All @@ -119,7 +119,7 @@ describe('ApolloClient', () => {
},
});

assert.deepEqual(client.readQuery({
assert.deepEqual<{}>(client.readQuery({
query: gql`query ($literal: Boolean, $value: Int = -1) {
a: field(literal: $literal, value: $value)
}`,
Expand All @@ -129,7 +129,7 @@ describe('ApolloClient', () => {
},
}), { a: 2 });

assert.deepEqual(client.readQuery({
assert.deepEqual<{}>(client.readQuery({
query: gql`query ($literal: Boolean, $value: Int = -1) {
a: field(literal: $literal, value: $value)
}`,
Expand Down Expand Up @@ -200,31 +200,31 @@ describe('ApolloClient', () => {
},
});

assert.deepEqual(
assert.deepEqual<{} | null>(
client.readFragment({ id: 'foo', fragment: gql`fragment fragmentFoo on Foo { e h { i } }` }),
{ __typename: 'Foo', e: 4, h: { __typename: 'Bar', i: 7 } },
);
assert.deepEqual(
assert.deepEqual<{} | null>(
client.readFragment({ id: 'foo', fragment: gql`fragment fragmentFoo on Foo { e f g h { i j k } }` }),
{ __typename: 'Foo', e: 4, f: 5, g: 6, h: { __typename: 'Bar', i: 7, j: 8, k: 9 } },
);
assert.deepEqual(
assert.deepEqual<{} | null>(
client.readFragment({ id: 'bar', fragment: gql`fragment fragmentBar on Bar { i }` }),
{ __typename: 'Bar', i: 7 },
);
assert.deepEqual(
assert.deepEqual<{} | null>(
client.readFragment({ id: 'bar', fragment: gql`fragment fragmentBar on Bar { i j k }` }),
{ __typename: 'Bar', i: 7, j: 8, k: 9 },
);
assert.deepEqual(
assert.deepEqual<{} | null>(
client.readFragment({
id: 'foo',
fragment: gql`fragment fragmentFoo on Foo { e f g h { i j k } } fragment fragmentBar on Bar { i j k }`,
fragmentName: 'fragmentFoo',
}),
{ __typename: 'Foo', e: 4, f: 5, g: 6, h: { __typename: 'Bar', i: 7, j: 8, k: 9 } },
);
assert.deepEqual(
assert.deepEqual<{} | null>(
client.readFragment({
id: 'bar',
fragment: gql`fragment fragmentFoo on Foo { e f g h { i j k } } fragment fragmentBar on Bar { i j k }`,
Expand All @@ -249,7 +249,7 @@ describe('ApolloClient', () => {
},
});

assert.deepEqual(client.readFragment({
assert.deepEqual<{} | null>(client.readFragment({
id: 'foo',
fragment: gql`
fragment foo on Foo {
Expand Down Expand Up @@ -287,7 +287,7 @@ describe('ApolloClient', () => {

assert.equal(client1.readFragment({ id: 'foo', fragment: gql`fragment fooFragment on Foo { a b c }` }), null);
assert.equal(client2.readFragment({ id: 'foo', fragment: gql`fragment fooFragment on Foo { a b c }` }), null);
assert.deepEqual(client3.readFragment({ id: 'foo', fragment: gql`fragment fooFragment on Foo { a b c }` }),
assert.deepEqual<{} | null>(client3.readFragment({ id: 'foo', fragment: gql`fragment fooFragment on Foo { a b c }` }),
{ __typename: 'Foo', a: 1, b: 2, c: 3 });
});
});
Expand Down Expand Up @@ -762,7 +762,7 @@ describe('ApolloClient', () => {
},
});

assert.deepEqual(
assert.deepEqual<{} | null>(
client.readFragment({ id: 'foo', fragment: gql`fragment x on Foo { a b c bar { d e f } }` }),
{ __typename: 'Foo', a: 1, b: 2, c: 3, bar: { d: 4, e: 5, f: 6, __typename: 'Bar' } },
);
Expand All @@ -773,7 +773,7 @@ describe('ApolloClient', () => {
data: { __typename: 'Foo', a: 7 },
});

assert.deepEqual(
assert.deepEqual<{} | null>(
client.readFragment({ id: 'foo', fragment: gql`fragment x on Foo { a b c bar { d e f } }` }),
{ __typename: 'Foo', a: 7, b: 2, c: 3, bar: { __typename: 'Bar', d: 4, e: 5, f: 6 } },
);
Expand All @@ -784,7 +784,7 @@ describe('ApolloClient', () => {
data: { __typename: 'Foo', bar: { __typename: 'Bar', d: 8 } },
});

assert.deepEqual(
assert.deepEqual<{} | null>(
client.readFragment({ id: 'foo', fragment: gql`fragment x on Foo { a b c bar { d e f } }` }),
{ __typename: 'Foo', a: 7, b: 2, c: 3, bar: { __typename: 'Bar', d: 8, e: 5, f: 6 } },
);
Expand All @@ -795,7 +795,7 @@ describe('ApolloClient', () => {
data: { __typename: 'Bar', e: 9 },
});

assert.deepEqual(
assert.deepEqual<{} | null>(
client.readFragment({ id: 'foo', fragment: gql`fragment x on Foo { a b c bar { d e f } }` }),
{ __typename: 'Foo', a: 7, b: 2, c: 3, bar: { __typename: 'Bar', d: 8, e: 9, f: 6 } },
);
Expand Down Expand Up @@ -832,7 +832,7 @@ describe('ApolloClient', () => {
data: { a: 1, b: 2, foo: { __typename: 'foo', c: 3, d: 4, bar: { key: 'foobar', __typename: 'bar', e: 5, f: 6 } } },
});

assert.deepEqual(
assert.deepEqual<{} | null>(
client.readQuery({ query: gql`{ a b foo { c d bar { key e f } } }` }),
{ a: 1, b: 2, foo: { __typename: 'foo', c: 3, d: 4, bar: { __typename: 'bar', key: 'foobar', e: 5, f: 6 } } },
);
Expand Down
20 changes: 12 additions & 8 deletions test/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import mockWatchQuery from './mocks/mockWatchQuery';
import mockNetworkInterface, {
ParsedRequest,
} from './mocks/mockNetworkInterface';
import { ObservableQuery } from '../src/core/ObservableQuery';
import {
ObservableQuery,
ApolloCurrentResult,
} from '../src/core/ObservableQuery';
import { ApolloQueryResult } from '../src/core/types';
import {
NetworkInterface,
} from '../src/transport/networkInterface';
Expand Down Expand Up @@ -834,7 +838,7 @@ describe('ObservableQuery', () => {
});

subscribeAndCount(done, observable, () => {
assert.deepEqual(observable.currentResult(), {
assert.deepEqual<ApolloCurrentResult<any>>(observable.currentResult(), {
data: dataOne,
loading: false,
networkStatus: 7,
Expand All @@ -843,14 +847,14 @@ describe('ObservableQuery', () => {
done();
});

assert.deepEqual(observable.currentResult(), {
assert.deepEqual<ApolloCurrentResult<any>>(observable.currentResult(), {
loading: true,
data: {},
networkStatus: 1,
partial: true,
});
setTimeout(wrap(done, () => {
assert.deepEqual(observable.currentResult(), {
assert.deepEqual<ApolloCurrentResult<any>>(observable.currentResult(), {
loading: true,
data: {},
networkStatus: 1,
Expand All @@ -877,7 +881,7 @@ describe('ObservableQuery', () => {
query,
variables,
});
assert.deepEqual(observable.currentResult(), {
assert.deepEqual<ApolloCurrentResult<any>>(observable.currentResult(), {
data: dataOne,
loading: false,
networkStatus: 7,
Expand Down Expand Up @@ -924,7 +928,7 @@ describe('ObservableQuery', () => {
variables,
fetchPolicy: 'network-only',
});
assert.deepEqual(observable.currentResult(), {
assert.deepEqual<ApolloCurrentResult<any>>(observable.currentResult(), {
data: dataOne,
loading: true,
networkStatus: 1,
Expand All @@ -936,7 +940,7 @@ describe('ObservableQuery', () => {
assert.deepEqual(subResult, { data, loading, networkStatus, stale: false });

if (handleCount === 1) {
assert.deepEqual(subResult, {
assert.deepEqual<ApolloQueryResult<any>>(subResult, {
data: dataTwo,
loading: false,
networkStatus: 7,
Expand Down Expand Up @@ -990,7 +994,7 @@ describe('ObservableQuery', () => {
assert.deepEqual(result, { data, loading, networkStatus, stale: false });

if (count === 1) {
assert.deepEqual(result, {
assert.deepEqual<ApolloQueryResult<any>>(result, {
data: dataOne,
loading: false,
networkStatus: 7,
Expand Down
6 changes: 3 additions & 3 deletions test/assign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ describe('assign', () => {
assert.strictEqual(assign(source2, { b: 2 }, { c: 3 }), source2);
assert.strictEqual(assign(source3, { b: 2 }, { c: 3 }, { d: 4 }), source3);

assert.deepEqual(source1, { a: 1, b: 2 });
assert.deepEqual(source2, { a: 1, b: 2, c: 3 });
assert.deepEqual(source3, { a: 1, b: 2, c: 3, d: 4 });
assert.deepEqual<{}>(source1, { a: 1, b: 2 });
assert.deepEqual<{}>(source2, { a: 1, b: 2, c: 3 });
assert.deepEqual<{}>(source3, { a: 1, b: 2, c: 3, d: 4 });
});
});
14 changes: 7 additions & 7 deletions test/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ describe('client', () => {
// then query for real
.then(() => client.query({ query, fetchPolicy: 'network-only' }))
.then((result) => {
assert.deepEqual(result.data, { myNumber: { n: 2 } });
assert.deepEqual<{}>(result.data, { myNumber: { n: 2 } });
});
});

Expand All @@ -1820,10 +1820,10 @@ describe('client', () => {
// then query for real
.then(() => client.query(options))
.then((result) => {
assert.deepEqual(result.data, { myNumber: { n: 1 } });
assert.deepEqual<{}>(result.data, { myNumber: { n: 1 } });

// Test that options weren't mutated, issue #339
assert.deepEqual(options, { query, fetchPolicy: 'network-only' });
assert.deepEqual<WatchQueryOptions>(options, { query, fetchPolicy: 'network-only' });
});
});

Expand All @@ -1845,14 +1845,14 @@ describe('client', () => {
return promise;
})
.then((result) => {
assert.deepEqual(result.data, { myNumber: { n: 1 } });
assert.deepEqual<{}>(result.data, { myNumber: { n: 1 } });
clock.tick(100);
const promise = client.query({ query, fetchPolicy: 'network-only' });
clock.tick(0);
return promise;
})
.then((result) => {
assert.deepEqual(result.data, { myNumber: { n: 2 } });
assert.deepEqual<{}>(result.data, { myNumber: { n: 2 } });
});
clock.tick(0);
return outerPromise;
Expand Down Expand Up @@ -2051,7 +2051,7 @@ describe('client', () => {
networkInterface.query({ query: firstQuery }),
networkInterface.query({ query: secondQuery }),
]).then((results) => {
assert.deepEqual(results, [firstResult, secondResult]);
assert.deepEqual<[ExecutionResult]>(results, [firstResult, secondResult]);
fetch = oldFetch;
done();
}).catch( e => {
Expand Down Expand Up @@ -2193,7 +2193,7 @@ describe('client', () => {
new Promise( (resolve, reject) =>
setTimeout(() => resolve(networkInterface.query({ query: secondQuery })), 10)),
]).then((results) => {
assert.deepEqual(results, [firstResult, secondResult]);
assert.deepEqual<[ExecutionResult]>(results, [firstResult, secondResult]);
fetch = oldFetch;
done();
}).catch( e => {
Expand Down
6 changes: 5 additions & 1 deletion test/customResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import ApolloClient, { toIdValue } from '../src';

import { NetworkStatus } from '../src/queries/networkStatus';

import {
ApolloQueryResult,
} from '../src/core/types';

describe('custom resolvers', () => {
it(`works for cache redirection`, () => {
const dataIdFromObject = (obj: any) => {
Expand Down Expand Up @@ -46,7 +50,7 @@ describe('custom resolvers', () => {
return client.query({ query: listQuery }).then(() => {
return client.query({ query: itemQuery });
}).then((itemResult) => {
assert.deepEqual(itemResult, {
assert.deepEqual<ApolloQueryResult<{}>>(itemResult, {
loading: false,
networkStatus: NetworkStatus.ready,
stale: false,
Expand Down
18 changes: 9 additions & 9 deletions test/mutationResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1291,13 +1291,13 @@ describe('mutation results', () => {
query ({ variables }) {
switch (count++) {
case 0:
assert.deepEqual(variables, { a: 1, b: 2 });
assert.deepEqual<Object | undefined>(variables, { a: 1, b: 2 });
return Promise.resolve({ data: { result: 'hello' } });
case 1:
assert.deepEqual(variables, { a: 1, c: 3 });
assert.deepEqual<Object | undefined>(variables, { a: 1, c: 3 });
return Promise.resolve({ data: { result: 'world' } });
case 2:
assert.deepEqual(variables, { a: undefined, b: 2, c: 3 });
assert.deepEqual<Object | undefined>(variables, { a: undefined, b: 2, c: 3 });
return Promise.resolve({ data: { result: 'goodbye' } });
case 3:
assert.deepEqual(variables, {});
Expand Down Expand Up @@ -1353,13 +1353,13 @@ describe('mutation results', () => {
query ({ variables }) {
switch (count++) {
case 0:
assert.deepEqual(variables, { a: 1, b: 'water' });
assert.deepEqual<Object | undefined>(variables, { a: 1, b: 'water' });
return Promise.resolve({ data: { result: 'hello' } });
case 1:
assert.deepEqual(variables, { a: 2, b: 'cheese', c: 3 });
assert.deepEqual<Object | undefined>(variables, { a: 2, b: 'cheese', c: 3 });
return Promise.resolve({ data: { result: 'world' } });
case 2:
assert.deepEqual(variables, { a: 1, b: 'cheese', c: 3 });
assert.deepEqual<Object | undefined>(variables, { a: 1, b: 'cheese', c: 3 });
return Promise.resolve({ data: { result: 'goodbye' } });
default:
return Promise.reject(new Error('Too many network calls.'));
Expand Down Expand Up @@ -1408,13 +1408,13 @@ describe('mutation results', () => {
query ({ variables }) {
switch (count++) {
case 0:
assert.deepEqual(variables, { a: 1, b: 2, c: null });
assert.deepEqual<Object | undefined>(variables, { a: 1, b: 2, c: null });
return Promise.resolve({ data: { result: 'hello' } });
case 1:
assert.deepEqual(variables, { a: 1, b: null, c: 3 });
assert.deepEqual<Object | undefined>(variables, { a: 1, b: null, c: 3 });
return Promise.resolve({ data: { result: 'world' } });
case 2:
assert.deepEqual(variables, { a: null, b: null, c: null });
assert.deepEqual<Object | undefined>(variables, { a: null, b: null, c: null });
return Promise.resolve({ data: { result: 'moon' } });
default:
return Promise.reject(new Error('Too many network calls.'));
Expand Down
Loading

0 comments on commit b3c3efa

Please sign in to comment.