diff --git a/.api-reports/api-report-cache.md b/.api-reports/api-report-cache.md index e10f450c8b7..97cea465367 100644 --- a/.api-reports/api-report-cache.md +++ b/.api-reports/api-report-cache.md @@ -90,7 +90,7 @@ namespace Cache_2 { // (undocumented) interface BatchOptions, TUpdateResult = void> { // (undocumented) - onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff: Cache_2.DiffResult | undefined) => any; + onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff?: Cache_2.DiffResult | undefined) => any; // (undocumented) optimistic?: string | boolean; // (undocumented) @@ -894,7 +894,7 @@ export type StoreValue = number | string | string[] | Reference | Reference[] | class Stump extends Layer { constructor(root: EntityStore.Root); // (undocumented) - merge(): any; + merge(older: string | StoreObject, newer: string | StoreObject): void; // (undocumented) removeLayer(): this; } diff --git a/.api-reports/api-report-core.md b/.api-reports/api-report-core.md index 29a4f1286af..fd6d4166e6f 100644 --- a/.api-reports/api-report-core.md +++ b/.api-reports/api-report-core.md @@ -298,7 +298,7 @@ namespace Cache_2 { // (undocumented) interface BatchOptions, TUpdateResult = void> { // (undocumented) - onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff: Cache_2.DiffResult | undefined) => any; + onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff?: Cache_2.DiffResult | undefined) => any; // (undocumented) optimistic?: string | boolean; // (undocumented) @@ -433,7 +433,7 @@ class Concast extends Observable { // (undocumented) cancel: (reason: any) => void; // (undocumented) - readonly promise: Promise; + readonly promise: Promise; // (undocumented) removeObserver(observer: Observer): void; } @@ -929,8 +929,6 @@ export class HttpLink extends ApolloLink { constructor(options?: HttpOptions); // (undocumented) options: HttpOptions; - // (undocumented) - requester: RequestHandler; } // @public (undocumented) @@ -1164,15 +1162,13 @@ class LocalState { // Warning: (ae-forgotten-export) The symbol "LocalStateOptions" needs to be exported by the entry point index.d.ts constructor({ cache, client, resolvers, fragmentMatcher, }: LocalStateOptions); // (undocumented) - addExportedVariables(document: DocumentNode, variables?: OperationVariables, context?: {}): Promise<{ - [x: string]: any; - }>; + addExportedVariables(document: DocumentNode, variables?: TVars, context?: {}): Promise; // (undocumented) addResolvers(resolvers: Resolvers | Resolvers[]): void; // (undocumented) clientQuery(document: DocumentNode): DocumentNode | null; // (undocumented) - getFragmentMatcher(): FragmentMatcher; + getFragmentMatcher(): FragmentMatcher | undefined; // (undocumented) getResolvers(): Resolvers; // (undocumented) @@ -1553,7 +1549,7 @@ export type OptimisticStoreItem = { }; // @public (undocumented) -type OptionsUnion = WatchQueryOptions | QueryOptions | MutationOptions; +type OptionsUnion = WatchQueryOptions | QueryOptions | MutationOptions; // @public (undocumented) export function parseAndCheckHttpResponse(operations: Operation | Operation[]): (response: Response) => Promise; @@ -1633,7 +1629,7 @@ class QueryInfo { document: DocumentNode; variables: Record | undefined; networkStatus?: NetworkStatus; - observableQuery?: ObservableQuery; + observableQuery?: ObservableQuery; lastRequestId?: number; }): this; // (undocumented) @@ -1655,7 +1651,7 @@ class QueryInfo { // (undocumented) notify(): void; // (undocumented) - readonly observableQuery: ObservableQuery | null; + readonly observableQuery: ObservableQuery | null; // (undocumented) readonly queryId: string; // (undocumented) @@ -1665,7 +1661,7 @@ class QueryInfo { // (undocumented) setDiff(diff: Cache_2.DiffResult | null): void; // (undocumented) - setObservableQuery(oq: ObservableQuery | null): void; + setObservableQuery(oq: ObservableQuery | null): void; // (undocumented) stop(): void; // (undocumented) @@ -1939,7 +1935,7 @@ export interface Resolvers { // // @public (undocumented) export function rewriteURIForGET(chosenURI: string, body: Body_2): { - parseError: any; + parseError: unknown; newURI?: undefined; } | { newURI: string; @@ -2022,7 +2018,7 @@ export type StoreValue = number | string | string[] | Reference | Reference[] | class Stump extends Layer { constructor(root: EntityStore.Root); // (undocumented) - merge(): any; + merge(older: string | StoreObject, newer: string | StoreObject): void; // (undocumented) removeLayer(): this; } @@ -2186,11 +2182,11 @@ interface WriteContext extends ReadMergeModifyContext { // src/cache/inmemory/policies.ts:167:3 - (ae-forgotten-export) The symbol "KeySpecifier" needs to be exported by the entry point index.d.ts // src/cache/inmemory/policies.ts:167:3 - (ae-forgotten-export) The symbol "KeyArgsFunction" needs to be exported by the entry point index.d.ts // src/cache/inmemory/types.ts:126:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts -// src/core/ObservableQuery.ts:112:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts -// src/core/ObservableQuery.ts:113:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:116:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:149:5 - (ae-forgotten-export) The symbol "LocalState" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:378:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:113:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:114:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:117:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:150:5 - (ae-forgotten-export) The symbol "LocalState" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:379:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/watchQueryOptions.ts:191:3 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts // src/link/http/selectHttpOptionsAndBody.ts:128:32 - (ae-forgotten-export) The symbol "HttpQueryOptions" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report-link_http.md b/.api-reports/api-report-link_http.md index 09b1e6459dd..8d6da95e4d4 100644 --- a/.api-reports/api-report-link_http.md +++ b/.api-reports/api-report-link_http.md @@ -181,8 +181,6 @@ export class HttpLink extends ApolloLink { constructor(options?: HttpOptions); // (undocumented) options: HttpOptions; - // (undocumented) - requester: RequestHandler; } // @public (undocumented) @@ -278,7 +276,7 @@ type RequestHandler = (operation: Operation, forward: NextLink) => Observable, TUpdateResult = void> { // (undocumented) - onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff: Cache_2.DiffResult | undefined) => any; + onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff?: Cache_2.DiffResult | undefined) => any; // (undocumented) optimistic?: string | boolean; // (undocumented) @@ -552,7 +552,7 @@ class Concast extends Observable { // (undocumented) cancel: (reason: any) => void; // (undocumented) - readonly promise: Promise; + readonly promise: Promise; // (undocumented) removeObserver(observer: Observer): void; } @@ -1021,15 +1021,13 @@ class LocalState { // Warning: (ae-forgotten-export) The symbol "LocalStateOptions" needs to be exported by the entry point index.d.ts constructor({ cache, client, resolvers, fragmentMatcher, }: LocalStateOptions); // (undocumented) - addExportedVariables(document: DocumentNode, variables?: OperationVariables, context?: {}): Promise<{ - [x: string]: any; - }>; + addExportedVariables(document: DocumentNode, variables?: TVars, context?: {}): Promise; // (undocumented) addResolvers(resolvers: Resolvers | Resolvers[]): void; // (undocumented) clientQuery(document: DocumentNode): DocumentNode | null; // (undocumented) - getFragmentMatcher(): FragmentMatcher; + getFragmentMatcher(): FragmentMatcher | undefined; // (undocumented) getResolvers(): Resolvers; // (undocumented) @@ -1452,7 +1450,7 @@ class QueryInfo { document: DocumentNode; variables: Record | undefined; networkStatus?: NetworkStatus; - observableQuery?: ObservableQuery; + observableQuery?: ObservableQuery; lastRequestId?: number; }): this; // (undocumented) @@ -1476,7 +1474,7 @@ class QueryInfo { // (undocumented) notify(): void; // (undocumented) - readonly observableQuery: ObservableQuery | null; + readonly observableQuery: ObservableQuery | null; // (undocumented) readonly queryId: string; // (undocumented) @@ -1486,7 +1484,7 @@ class QueryInfo { // (undocumented) setDiff(diff: Cache_2.DiffResult | null): void; // (undocumented) - setObservableQuery(oq: ObservableQuery | null): void; + setObservableQuery(oq: ObservableQuery | null): void; // (undocumented) stop(): void; // (undocumented) @@ -2206,18 +2204,18 @@ interface WatchQueryOptions, TUpdateResult = void> { // (undocumented) - onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff: Cache_2.DiffResult | undefined) => any; + onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff?: Cache_2.DiffResult | undefined) => any; // (undocumented) optimistic?: string | boolean; // (undocumented) @@ -491,7 +491,7 @@ class Concast extends Observable { // (undocumented) cancel: (reason: any) => void; // (undocumented) - readonly promise: Promise; + readonly promise: Promise; // (undocumented) removeObserver(observer: Observer): void; } @@ -819,15 +819,13 @@ class LocalState { // Warning: (ae-forgotten-export) The symbol "LocalStateOptions" needs to be exported by the entry point index.d.ts constructor({ cache, client, resolvers, fragmentMatcher, }: LocalStateOptions); // (undocumented) - addExportedVariables(document: DocumentNode, variables?: OperationVariables, context?: {}): Promise<{ - [x: string]: any; - }>; + addExportedVariables(document: DocumentNode, variables?: TVars, context?: {}): Promise; // (undocumented) addResolvers(resolvers: Resolvers | Resolvers[]): void; // (undocumented) clientQuery(document: DocumentNode): DocumentNode | null; // (undocumented) - getFragmentMatcher(): FragmentMatcher; + getFragmentMatcher(): FragmentMatcher | undefined; // (undocumented) getResolvers(): Resolvers; // (undocumented) @@ -1256,7 +1254,7 @@ class QueryInfo { document: DocumentNode; variables: Record | undefined; networkStatus?: NetworkStatus; - observableQuery?: ObservableQuery; + observableQuery?: ObservableQuery; lastRequestId?: number; }): this; // (undocumented) @@ -1280,7 +1278,7 @@ class QueryInfo { // (undocumented) notify(): void; // (undocumented) - readonly observableQuery: ObservableQuery | null; + readonly observableQuery: ObservableQuery | null; // (undocumented) readonly queryId: string; // (undocumented) @@ -1290,7 +1288,7 @@ class QueryInfo { // (undocumented) setDiff(diff: Cache_2.DiffResult | null): void; // (undocumented) - setObservableQuery(oq: ObservableQuery | null): void; + setObservableQuery(oq: ObservableQuery | null): void; // (undocumented) stop(): void; // (undocumented) @@ -1738,11 +1736,11 @@ interface WatchQueryOptions, TUpdateResult = void> { // (undocumented) - onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff: Cache_2.DiffResult | undefined) => any; + onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff?: Cache_2.DiffResult | undefined) => any; // (undocumented) optimistic?: string | boolean; // (undocumented) @@ -476,7 +476,7 @@ class Concast extends Observable { // (undocumented) cancel: (reason: any) => void; // (undocumented) - readonly promise: Promise; + readonly promise: Promise; // (undocumented) removeObserver(observer: Observer): void; } @@ -807,15 +807,13 @@ class LocalState { // Warning: (ae-forgotten-export) The symbol "LocalStateOptions" needs to be exported by the entry point index.d.ts constructor({ cache, client, resolvers, fragmentMatcher, }: LocalStateOptions); // (undocumented) - addExportedVariables(document: DocumentNode, variables?: OperationVariables, context?: {}): Promise<{ - [x: string]: any; - }>; + addExportedVariables(document: DocumentNode, variables?: TVars, context?: {}): Promise; // (undocumented) addResolvers(resolvers: Resolvers | Resolvers[]): void; // (undocumented) clientQuery(document: DocumentNode): DocumentNode | null; // (undocumented) - getFragmentMatcher(): FragmentMatcher; + getFragmentMatcher(): FragmentMatcher | undefined; // (undocumented) getResolvers(): Resolvers; // (undocumented) @@ -1166,7 +1164,7 @@ class QueryInfo { document: DocumentNode; variables: Record | undefined; networkStatus?: NetworkStatus; - observableQuery?: ObservableQuery; + observableQuery?: ObservableQuery; lastRequestId?: number; }): this; // (undocumented) @@ -1190,7 +1188,7 @@ class QueryInfo { // (undocumented) notify(): void; // (undocumented) - readonly observableQuery: ObservableQuery | null; + readonly observableQuery: ObservableQuery | null; // (undocumented) readonly queryId: string; // (undocumented) @@ -1200,7 +1198,7 @@ class QueryInfo { // (undocumented) setDiff(diff: Cache_2.DiffResult | null): void; // (undocumented) - setObservableQuery(oq: ObservableQuery | null): void; + setObservableQuery(oq: ObservableQuery | null): void; // (undocumented) stop(): void; // (undocumented) @@ -1636,11 +1634,11 @@ interface WatchQueryOptions, TUpdateResult = void> { // (undocumented) - onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff: Cache_2.DiffResult | undefined) => any; + onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff?: Cache_2.DiffResult | undefined) => any; // (undocumented) optimistic?: string | boolean; // (undocumented) @@ -468,7 +468,7 @@ class Concast extends Observable { // (undocumented) cancel: (reason: any) => void; // (undocumented) - readonly promise: Promise; + readonly promise: Promise; // (undocumented) removeObserver(observer: Observer): void; } @@ -817,15 +817,13 @@ class LocalState { // Warning: (ae-forgotten-export) The symbol "LocalStateOptions" needs to be exported by the entry point index.d.ts constructor({ cache, client, resolvers, fragmentMatcher, }: LocalStateOptions); // (undocumented) - addExportedVariables(document: DocumentNode, variables?: OperationVariables, context?: {}): Promise<{ - [x: string]: any; - }>; + addExportedVariables(document: DocumentNode, variables?: TVars, context?: {}): Promise; // (undocumented) addResolvers(resolvers: Resolvers | Resolvers[]): void; // (undocumented) clientQuery(document: DocumentNode): DocumentNode | null; // (undocumented) - getFragmentMatcher(): FragmentMatcher; + getFragmentMatcher(): FragmentMatcher | undefined; // (undocumented) getResolvers(): Resolvers; // (undocumented) @@ -1234,7 +1232,7 @@ class QueryInfo { document: DocumentNode; variables: Record | undefined; networkStatus?: NetworkStatus; - observableQuery?: ObservableQuery; + observableQuery?: ObservableQuery; lastRequestId?: number; }): this; // (undocumented) @@ -1258,7 +1256,7 @@ class QueryInfo { // (undocumented) notify(): void; // (undocumented) - readonly observableQuery: ObservableQuery | null; + readonly observableQuery: ObservableQuery | null; // (undocumented) readonly queryId: string; // (undocumented) @@ -1268,7 +1266,7 @@ class QueryInfo { // (undocumented) setDiff(diff: Cache_2.DiffResult | null): void; // (undocumented) - setObservableQuery(oq: ObservableQuery | null): void; + setObservableQuery(oq: ObservableQuery | null): void; // (undocumented) stop(): void; // (undocumented) @@ -1680,11 +1678,11 @@ export function withSubscription, TUpdateResult = void> { // (undocumented) - onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff: Cache_2.DiffResult | undefined) => any; + onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff?: Cache_2.DiffResult | undefined) => any; // (undocumented) optimistic?: string | boolean; // (undocumented) @@ -520,7 +520,7 @@ class Concast extends Observable { // (undocumented) cancel: (reason: any) => void; // (undocumented) - readonly promise: Promise; + readonly promise: Promise; // (undocumented) removeObserver(observer: Observer): void; } @@ -969,15 +969,13 @@ class LocalState { // Warning: (ae-forgotten-export) The symbol "LocalStateOptions" needs to be exported by the entry point index.d.ts constructor({ cache, client, resolvers, fragmentMatcher, }: LocalStateOptions); // (undocumented) - addExportedVariables(document: DocumentNode, variables?: OperationVariables, context?: {}): Promise<{ - [x: string]: any; - }>; + addExportedVariables(document: DocumentNode, variables?: TVars, context?: {}): Promise; // (undocumented) addResolvers(resolvers: Resolvers | Resolvers[]): void; // (undocumented) clientQuery(document: DocumentNode): DocumentNode | null; // (undocumented) - getFragmentMatcher(): FragmentMatcher; + getFragmentMatcher(): FragmentMatcher | undefined; // (undocumented) getResolvers(): Resolvers; // (undocumented) @@ -1380,7 +1378,7 @@ class QueryInfo { document: DocumentNode; variables: Record | undefined; networkStatus?: NetworkStatus; - observableQuery?: ObservableQuery; + observableQuery?: ObservableQuery; lastRequestId?: number; }): this; // (undocumented) @@ -1404,7 +1402,7 @@ class QueryInfo { // (undocumented) notify(): void; // (undocumented) - readonly observableQuery: ObservableQuery | null; + readonly observableQuery: ObservableQuery | null; // (undocumented) readonly queryId: string; // (undocumented) @@ -1414,7 +1412,7 @@ class QueryInfo { // (undocumented) setDiff(diff: Cache_2.DiffResult | null): void; // (undocumented) - setObservableQuery(oq: ObservableQuery | null): void; + setObservableQuery(oq: ObservableQuery | null): void; // (undocumented) stop(): void; // (undocumented) @@ -2097,18 +2095,18 @@ interface WatchQueryOptions, TUpdateResult = void> { // (undocumented) - onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff: Cache_2.DiffResult | undefined) => any; + onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff?: Cache_2.DiffResult | undefined) => any; // (undocumented) optimistic?: string | boolean; // (undocumented) @@ -447,7 +447,7 @@ class Concast extends Observable { // (undocumented) cancel: (reason: any) => void; // (undocumented) - readonly promise: Promise; + readonly promise: Promise; // (undocumented) removeObserver(observer: Observer): void; } @@ -794,15 +794,13 @@ class LocalState { // Warning: (ae-forgotten-export) The symbol "LocalStateOptions" needs to be exported by the entry point index.d.ts constructor({ cache, client, resolvers, fragmentMatcher, }: LocalStateOptions); // (undocumented) - addExportedVariables(document: DocumentNode, variables?: OperationVariables, context?: {}): Promise<{ - [x: string]: any; - }>; + addExportedVariables(document: DocumentNode, variables?: TVars, context?: {}): Promise; // (undocumented) addResolvers(resolvers: Resolvers | Resolvers[]): void; // (undocumented) clientQuery(document: DocumentNode): DocumentNode | null; // (undocumented) - getFragmentMatcher(): FragmentMatcher; + getFragmentMatcher(): FragmentMatcher | undefined; // (undocumented) getResolvers(): Resolvers; // (undocumented) @@ -1153,7 +1151,7 @@ class QueryInfo { document: DocumentNode; variables: Record | undefined; networkStatus?: NetworkStatus; - observableQuery?: ObservableQuery; + observableQuery?: ObservableQuery; lastRequestId?: number; }): this; // (undocumented) @@ -1177,7 +1175,7 @@ class QueryInfo { // (undocumented) notify(): void; // (undocumented) - readonly observableQuery: ObservableQuery | null; + readonly observableQuery: ObservableQuery | null; // (undocumented) readonly queryId: string; // (undocumented) @@ -1187,7 +1185,7 @@ class QueryInfo { // (undocumented) setDiff(diff: Cache_2.DiffResult | null): void; // (undocumented) - setObservableQuery(oq: ObservableQuery | null): void; + setObservableQuery(oq: ObservableQuery | null): void; // (undocumented) stop(): void; // (undocumented) @@ -1623,11 +1621,11 @@ interface WatchQueryOptions, TUpdateResult = void> { // (undocumented) - onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff: Cache_2.DiffResult | undefined) => any; + onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff?: Cache_2.DiffResult | undefined) => any; // (undocumented) optimistic?: string | boolean; // (undocumented) @@ -431,7 +431,7 @@ class Concast extends Observable { // (undocumented) cancel: (reason: any) => void; // (undocumented) - readonly promise: Promise; + readonly promise: Promise; // (undocumented) removeObserver(observer: Observer): void; } @@ -761,7 +761,7 @@ function isReference(obj: any): obj is Reference; type IsStrictlyAny = UnionToIntersection> extends never ? true : false; // @public (undocumented) -export const itAsync: ((message: string, callback: (resolve: (result?: any) => void, reject: (reason?: any) => void) => any, timeout?: number | undefined) => any) & { +export const itAsync: ((this: unknown, message: string, callback: (resolve: (result?: any) => void, reject: (reason?: any) => void) => any, timeout?: number | undefined) => void) & { only: (message: string, callback: (resolve: (result?: any) => void, reject: (reason?: any) => void) => any, timeout?: number) => void; skip: (message: string, callback: (resolve: (result?: any) => void, reject: (reason?: any) => void) => any, timeout?: number) => void; todo: (message: string, callback: (resolve: (result?: any) => void, reject: (reason?: any) => void) => any, timeout?: number) => void; @@ -772,15 +772,13 @@ class LocalState { // Warning: (ae-forgotten-export) The symbol "LocalStateOptions" needs to be exported by the entry point index.d.ts constructor({ cache, client, resolvers, fragmentMatcher, }: LocalStateOptions); // (undocumented) - addExportedVariables(document: DocumentNode, variables?: OperationVariables, context?: {}): Promise<{ - [x: string]: any; - }>; + addExportedVariables(document: DocumentNode, variables?: TVars, context?: {}): Promise; // (undocumented) addResolvers(resolvers: Resolvers | Resolvers[]): void; // (undocumented) clientQuery(document: DocumentNode): DocumentNode | null; // (undocumented) - getFragmentMatcher(): FragmentMatcher; + getFragmentMatcher(): FragmentMatcher | undefined; // (undocumented) getResolvers(): Resolvers; // (undocumented) @@ -951,7 +949,7 @@ export class MockSubscriptionLink extends ApolloLink { // (undocumented) onUnsubscribe(listener: any): void; // (undocumented) - operation: Operation; + operation?: Operation; // (undocumented) request(operation: Operation): Observable; // (undocumented) @@ -1231,7 +1229,7 @@ class QueryInfo { document: DocumentNode; variables: Record | undefined; networkStatus?: NetworkStatus; - observableQuery?: ObservableQuery; + observableQuery?: ObservableQuery; lastRequestId?: number; }): this; // (undocumented) @@ -1255,7 +1253,7 @@ class QueryInfo { // (undocumented) notify(): void; // (undocumented) - readonly observableQuery: ObservableQuery | null; + readonly observableQuery: ObservableQuery | null; // (undocumented) readonly queryId: string; // (undocumented) @@ -1265,7 +1263,7 @@ class QueryInfo { // (undocumented) setDiff(diff: Cache_2.DiffResult | null): void; // (undocumented) - setObservableQuery(oq: ObservableQuery | null): void; + setObservableQuery(oq: ObservableQuery | null): void; // (undocumented) stop(): void; // (undocumented) @@ -1673,11 +1671,11 @@ export function withWarningSpy(it: (...args: TArgs // src/cache/core/types/common.ts:100:3 - (ae-forgotten-export) The symbol "StorageType" needs to be exported by the entry point index.d.ts // src/core/ApolloClient.ts:47:3 - (ae-forgotten-export) The symbol "UriFunction" needs to be exported by the entry point index.d.ts // src/core/LocalState.ts:46:5 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts -// src/core/ObservableQuery.ts:112:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts -// src/core/ObservableQuery.ts:113:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:116:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:149:5 - (ae-forgotten-export) The symbol "LocalState" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:378:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:113:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:114:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:117:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:150:5 - (ae-forgotten-export) The symbol "LocalState" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:379:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/types.ts:158:3 - (ae-forgotten-export) The symbol "ApolloError" needs to be exported by the entry point index.d.ts // src/core/types.ts:160:3 - (ae-forgotten-export) The symbol "NetworkStatus" needs to be exported by the entry point index.d.ts // src/core/types.ts:178:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report-testing_core.md b/.api-reports/api-report-testing_core.md index a95a55f8e2a..717e6e70674 100644 --- a/.api-reports/api-report-testing_core.md +++ b/.api-reports/api-report-testing_core.md @@ -309,7 +309,7 @@ namespace Cache_2 { // (undocumented) interface BatchOptions, TUpdateResult = void> { // (undocumented) - onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff: Cache_2.DiffResult | undefined) => any; + onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff?: Cache_2.DiffResult | undefined) => any; // (undocumented) optimistic?: string | boolean; // (undocumented) @@ -430,7 +430,7 @@ class Concast extends Observable { // (undocumented) cancel: (reason: any) => void; // (undocumented) - readonly promise: Promise; + readonly promise: Promise; // (undocumented) removeObserver(observer: Observer): void; } @@ -760,7 +760,7 @@ function isReference(obj: any): obj is Reference; type IsStrictlyAny = UnionToIntersection> extends never ? true : false; // @public (undocumented) -export const itAsync: ((message: string, callback: (resolve: (result?: any) => void, reject: (reason?: any) => void) => any, timeout?: number | undefined) => any) & { +export const itAsync: ((this: unknown, message: string, callback: (resolve: (result?: any) => void, reject: (reason?: any) => void) => any, timeout?: number | undefined) => void) & { only: (message: string, callback: (resolve: (result?: any) => void, reject: (reason?: any) => void) => any, timeout?: number) => void; skip: (message: string, callback: (resolve: (result?: any) => void, reject: (reason?: any) => void) => any, timeout?: number) => void; todo: (message: string, callback: (resolve: (result?: any) => void, reject: (reason?: any) => void) => any, timeout?: number) => void; @@ -771,15 +771,13 @@ class LocalState { // Warning: (ae-forgotten-export) The symbol "LocalStateOptions" needs to be exported by the entry point index.d.ts constructor({ cache, client, resolvers, fragmentMatcher, }: LocalStateOptions); // (undocumented) - addExportedVariables(document: DocumentNode, variables?: OperationVariables, context?: {}): Promise<{ - [x: string]: any; - }>; + addExportedVariables(document: DocumentNode, variables?: TVars, context?: {}): Promise; // (undocumented) addResolvers(resolvers: Resolvers | Resolvers[]): void; // (undocumented) clientQuery(document: DocumentNode): DocumentNode | null; // (undocumented) - getFragmentMatcher(): FragmentMatcher; + getFragmentMatcher(): FragmentMatcher | undefined; // (undocumented) getResolvers(): Resolvers; // (undocumented) @@ -905,7 +903,7 @@ export class MockSubscriptionLink extends ApolloLink { // (undocumented) onUnsubscribe(listener: any): void; // (undocumented) - operation: Operation; + operation?: Operation; // (undocumented) request(operation: Operation): Observable; // (undocumented) @@ -1185,7 +1183,7 @@ class QueryInfo { document: DocumentNode; variables: Record | undefined; networkStatus?: NetworkStatus; - observableQuery?: ObservableQuery; + observableQuery?: ObservableQuery; lastRequestId?: number; }): this; // (undocumented) @@ -1209,7 +1207,7 @@ class QueryInfo { // (undocumented) notify(): void; // (undocumented) - readonly observableQuery: ObservableQuery | null; + readonly observableQuery: ObservableQuery | null; // (undocumented) readonly queryId: string; // (undocumented) @@ -1219,7 +1217,7 @@ class QueryInfo { // (undocumented) setDiff(diff: Cache_2.DiffResult | null): void; // (undocumented) - setObservableQuery(oq: ObservableQuery | null): void; + setObservableQuery(oq: ObservableQuery | null): void; // (undocumented) stop(): void; // (undocumented) @@ -1629,11 +1627,11 @@ export function withWarningSpy(it: (...args: TArgs // src/cache/core/types/common.ts:100:3 - (ae-forgotten-export) The symbol "StorageType" needs to be exported by the entry point index.d.ts // src/core/ApolloClient.ts:47:3 - (ae-forgotten-export) The symbol "UriFunction" needs to be exported by the entry point index.d.ts // src/core/LocalState.ts:46:5 - (ae-forgotten-export) The symbol "FragmentMap" needs to be exported by the entry point index.d.ts -// src/core/ObservableQuery.ts:112:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts -// src/core/ObservableQuery.ts:113:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:116:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:149:5 - (ae-forgotten-export) The symbol "LocalState" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:378:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:113:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:114:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:117:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:150:5 - (ae-forgotten-export) The symbol "LocalState" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:379:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/types.ts:158:3 - (ae-forgotten-export) The symbol "ApolloError" needs to be exported by the entry point index.d.ts // src/core/types.ts:160:3 - (ae-forgotten-export) The symbol "NetworkStatus" needs to be exported by the entry point index.d.ts // src/core/types.ts:178:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report-utilities.md b/.api-reports/api-report-utilities.md index 90e3cbaae41..3b3396f5a87 100644 --- a/.api-reports/api-report-utilities.md +++ b/.api-reports/api-report-utilities.md @@ -352,7 +352,7 @@ namespace Cache_2 { // (undocumented) interface BatchOptions, TUpdateResult = void> { // (undocumented) - onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff: Cache_2.DiffResult | undefined) => any; + onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff?: Cache_2.DiffResult | undefined) => any; // (undocumented) optimistic?: string | boolean; // (undocumented) @@ -512,7 +512,7 @@ export class Concast extends Observable { // (undocumented) cancel: (reason: any) => void; // (undocumented) - readonly promise: Promise; + readonly promise: Promise; // (undocumented) removeObserver(observer: Observer): void; } @@ -1395,15 +1395,13 @@ class LocalState { // Warning: (ae-forgotten-export) The symbol "LocalStateOptions" needs to be exported by the entry point index.d.ts constructor({ cache, client, resolvers, fragmentMatcher, }: LocalStateOptions); // (undocumented) - addExportedVariables(document: DocumentNode, variables?: OperationVariables, context?: {}): Promise<{ - [x: string]: any; - }>; + addExportedVariables(document: DocumentNode, variables?: TVars, context?: {}): Promise; // (undocumented) addResolvers(resolvers: Resolvers | Resolvers[]): void; // (undocumented) clientQuery(document: DocumentNode): DocumentNode | null; // (undocumented) - getFragmentMatcher(): FragmentMatcher; + getFragmentMatcher(): FragmentMatcher | undefined; // (undocumented) getResolvers(): Resolvers; // (undocumented) @@ -1811,7 +1809,7 @@ interface Operation { type OperationVariables = Record; // @public (undocumented) -type OptionsUnion = WatchQueryOptions | QueryOptions | MutationOptions; +type OptionsUnion = WatchQueryOptions | QueryOptions | MutationOptions; // @public (undocumented) type Path = ReadonlyArray; @@ -1896,7 +1894,7 @@ class QueryInfo { document: DocumentNode; variables: Record | undefined; networkStatus?: NetworkStatus; - observableQuery?: ObservableQuery; + observableQuery?: ObservableQuery; lastRequestId?: number; }): this; // (undocumented) @@ -1920,7 +1918,7 @@ class QueryInfo { // (undocumented) notify(): void; // (undocumented) - readonly observableQuery: ObservableQuery | null; + readonly observableQuery: ObservableQuery | null; // (undocumented) readonly queryId: string; // (undocumented) @@ -1930,7 +1928,7 @@ class QueryInfo { // (undocumented) setDiff(diff: Cache_2.DiffResult | null): void; // (undocumented) - setObservableQuery(oq: ObservableQuery | null): void; + setObservableQuery(oq: ObservableQuery | null): void; // (undocumented) stop(): void; // (undocumented) @@ -2316,7 +2314,7 @@ export function stripTypename(value: T): DeepOmit; class Stump extends Layer { constructor(root: EntityStore.Root); // (undocumented) - merge(): any; + merge(older: string | StoreObject, newer: string | StoreObject): void; // (undocumented) removeLayer(): this; } @@ -2512,11 +2510,11 @@ interface WriteContext extends ReadMergeModifyContext { // src/cache/inmemory/writeToStore.ts:65:7 - (ae-forgotten-export) The symbol "MergeTree" needs to be exported by the entry point index.d.ts // src/core/ApolloClient.ts:47:3 - (ae-forgotten-export) The symbol "UriFunction" needs to be exported by the entry point index.d.ts // src/core/LocalState.ts:71:3 - (ae-forgotten-export) The symbol "ApolloClient" needs to be exported by the entry point index.d.ts -// src/core/ObservableQuery.ts:112:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts -// src/core/ObservableQuery.ts:113:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:116:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:149:5 - (ae-forgotten-export) The symbol "LocalState" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:378:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:113:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:114:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:117:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:150:5 - (ae-forgotten-export) The symbol "LocalState" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:379:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/types.ts:158:3 - (ae-forgotten-export) The symbol "ApolloError" needs to be exported by the entry point index.d.ts // src/core/types.ts:160:3 - (ae-forgotten-export) The symbol "NetworkStatus" needs to be exported by the entry point index.d.ts // src/core/types.ts:178:3 - (ae-forgotten-export) The symbol "MutationQueryReducer" needs to be exported by the entry point index.d.ts diff --git a/.api-reports/api-report.md b/.api-reports/api-report.md index 231d1ada070..35954d0b1c0 100644 --- a/.api-reports/api-report.md +++ b/.api-reports/api-report.md @@ -403,7 +403,7 @@ namespace Cache_2 { // (undocumented) interface BatchOptions, TUpdateResult = void> { // (undocumented) - onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff: Cache_2.DiffResult | undefined) => any; + onWatchUpdated?: (this: TCache, watch: Cache_2.WatchOptions, diff: Cache_2.DiffResult, lastDiff?: Cache_2.DiffResult | undefined) => any; // (undocumented) optimistic?: string | boolean; // (undocumented) @@ -550,7 +550,7 @@ class Concast extends Observable { // (undocumented) cancel: (reason: any) => void; // (undocumented) - readonly promise: Promise; + readonly promise: Promise; // (undocumented) removeObserver(observer: Observer): void; } @@ -1107,8 +1107,6 @@ export class HttpLink extends ApolloLink { constructor(options?: HttpOptions); // (undocumented) options: HttpOptions; - // (undocumented) - requester: RequestHandler; } // @public (undocumented) @@ -1422,15 +1420,13 @@ class LocalState { // Warning: (ae-forgotten-export) The symbol "LocalStateOptions" needs to be exported by the entry point index.d.ts constructor({ cache, client, resolvers, fragmentMatcher, }: LocalStateOptions); // (undocumented) - addExportedVariables(document: DocumentNode, variables?: OperationVariables, context?: {}): Promise<{ - [x: string]: any; - }>; + addExportedVariables(document: DocumentNode, variables?: TVars, context?: {}): Promise; // (undocumented) addResolvers(resolvers: Resolvers | Resolvers[]): void; // (undocumented) clientQuery(document: DocumentNode): DocumentNode | null; // (undocumented) - getFragmentMatcher(): FragmentMatcher; + getFragmentMatcher(): FragmentMatcher | undefined; // (undocumented) getResolvers(): Resolvers; // (undocumented) @@ -1885,7 +1881,7 @@ export type OptimisticStoreItem = { }; // @public (undocumented) -type OptionsUnion = WatchQueryOptions | QueryOptions | MutationOptions; +type OptionsUnion = WatchQueryOptions | QueryOptions | MutationOptions; // @public (undocumented) export function parseAndCheckHttpResponse(operations: Operation | Operation[]): (response: Response) => Promise; @@ -2006,7 +2002,7 @@ class QueryInfo { document: DocumentNode; variables: Record | undefined; networkStatus?: NetworkStatus; - observableQuery?: ObservableQuery; + observableQuery?: ObservableQuery; lastRequestId?: number; }): this; // (undocumented) @@ -2028,7 +2024,7 @@ class QueryInfo { // (undocumented) notify(): void; // (undocumented) - readonly observableQuery: ObservableQuery | null; + readonly observableQuery: ObservableQuery | null; // (undocumented) readonly queryId: string; // (undocumented) @@ -2038,7 +2034,7 @@ class QueryInfo { // (undocumented) setDiff(diff: Cache_2.DiffResult | null): void; // (undocumented) - setObservableQuery(oq: ObservableQuery | null): void; + setObservableQuery(oq: ObservableQuery | null): void; // (undocumented) stop(): void; // (undocumented) @@ -2380,7 +2376,7 @@ export interface Resolvers { // // @public (undocumented) export function rewriteURIForGET(chosenURI: string, body: Body_2): { - parseError: any; + parseError: unknown; newURI?: undefined; } | { newURI: string; @@ -2469,7 +2465,7 @@ export type StoreValue = number | string | string[] | Reference | Reference[] | class Stump extends Layer { constructor(root: EntityStore.Root); // (undocumented) - merge(): any; + merge(older: string | StoreObject, newer: string | StoreObject): void; // (undocumented) removeLayer(): this; } @@ -2871,15 +2867,15 @@ interface WriteContext extends ReadMergeModifyContext { // src/cache/inmemory/policies.ts:167:3 - (ae-forgotten-export) The symbol "KeySpecifier" needs to be exported by the entry point index.d.ts // src/cache/inmemory/policies.ts:167:3 - (ae-forgotten-export) The symbol "KeyArgsFunction" needs to be exported by the entry point index.d.ts // src/cache/inmemory/types.ts:126:3 - (ae-forgotten-export) The symbol "KeyFieldsFunction" needs to be exported by the entry point index.d.ts -// src/core/ObservableQuery.ts:112:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts -// src/core/ObservableQuery.ts:113:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:116:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:149:5 - (ae-forgotten-export) The symbol "LocalState" needs to be exported by the entry point index.d.ts -// src/core/QueryManager.ts:378:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:113:5 - (ae-forgotten-export) The symbol "QueryManager" needs to be exported by the entry point index.d.ts +// src/core/ObservableQuery.ts:114:5 - (ae-forgotten-export) The symbol "QueryInfo" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:117:5 - (ae-forgotten-export) The symbol "MutationStoreValue" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:150:5 - (ae-forgotten-export) The symbol "LocalState" needs to be exported by the entry point index.d.ts +// src/core/QueryManager.ts:379:7 - (ae-forgotten-export) The symbol "UpdateQueries" needs to be exported by the entry point index.d.ts // src/core/watchQueryOptions.ts:191:3 - (ae-forgotten-export) The symbol "UpdateQueryFn" needs to be exported by the entry point index.d.ts // src/link/http/selectHttpOptionsAndBody.ts:128:32 - (ae-forgotten-export) The symbol "HttpQueryOptions" needs to be exported by the entry point index.d.ts -// src/react/hooks/useBackgroundQuery.ts:24:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts -// src/react/hooks/useBackgroundQuery.ts:25:3 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts +// src/react/hooks/useBackgroundQuery.ts:26:3 - (ae-forgotten-export) The symbol "FetchMoreFunction" needs to be exported by the entry point index.d.ts +// src/react/hooks/useBackgroundQuery.ts:27:3 - (ae-forgotten-export) The symbol "RefetchFunction" needs to be exported by the entry point index.d.ts // (No @packageDocumentation comment for this package) diff --git a/.changeset/chatty-plants-cheer.md b/.changeset/chatty-plants-cheer.md new file mode 100644 index 00000000000..79cd7b9cd19 --- /dev/null +++ b/.changeset/chatty-plants-cheer.md @@ -0,0 +1,5 @@ +--- +"@apollo/client": patch +--- + +Enable `strict` in tsconfig for the entire project. diff --git a/.size-limit.cjs b/.size-limit.cjs index 0ab7c9f0aef..427e2778948 100644 --- a/.size-limit.cjs +++ b/.size-limit.cjs @@ -1,7 +1,7 @@ const checks = [ { path: "dist/apollo-client.min.cjs", - limit: "37972", + limit: "37975", }, { path: "dist/main.cjs", @@ -10,7 +10,7 @@ const checks = [ { path: "dist/index.js", import: "{ ApolloClient, InMemoryCache, HttpLink }", - limit: "32017", + limit: "32019", }, ...[ "ApolloProvider", diff --git a/src/__tests__/ApolloClient.ts b/src/__tests__/ApolloClient.ts index 50c668f934c..993691abe0c 100644 --- a/src/__tests__/ApolloClient.ts +++ b/src/__tests__/ApolloClient.ts @@ -4,7 +4,6 @@ import { ApolloClient, ApolloError, DefaultOptions, - FetchPolicy, QueryOptions, makeReference, } from "../core"; @@ -2126,8 +2125,8 @@ describe("ApolloClient", () => { } `; - ["network-only", "cache-and-network"].forEach( - (fetchPolicy: FetchPolicy) => { + (["network-only", "cache-and-network"] as const).forEach( + (fetchPolicy) => { const observable = client.watchQuery({ query, fetchPolicy, @@ -2156,13 +2155,15 @@ describe("ApolloClient", () => { } `; - [ - "cache-first", - "cache-and-network", - "network-only", - "cache-only", - "no-cache", - ].forEach((fetchPolicy: FetchPolicy) => { + ( + [ + "cache-first", + "cache-and-network", + "network-only", + "cache-only", + "no-cache", + ] as const + ).forEach((fetchPolicy) => { const observable = client.watchQuery({ query, fetchPolicy, diff --git a/src/__tests__/client.ts b/src/__tests__/client.ts index eb13692d37b..2fd8c29f187 100644 --- a/src/__tests__/client.ts +++ b/src/__tests__/client.ts @@ -1821,7 +1821,7 @@ describe("client", () => { link, cache: new InMemoryCache({ - dataIdFromObject: (obj: { id: any }) => obj.id, + dataIdFromObject: (obj: any) => obj.id, addTypename: false, }), }); @@ -1870,7 +1870,7 @@ describe("client", () => { callback(); throw new Error("not reached"); } catch (thrown) { - expect(thrown.message).toBe(cacheAndNetworkError); + expect((thrown as Error).message).toBe(cacheAndNetworkError); } } diff --git a/src/__tests__/graphqlSubscriptions.ts b/src/__tests__/graphqlSubscriptions.ts index 8b46eb01c26..2f4d66228d9 100644 --- a/src/__tests__/graphqlSubscriptions.ts +++ b/src/__tests__/graphqlSubscriptions.ts @@ -488,7 +488,7 @@ describe("GraphQL Subscriptions", () => { client.subscribe(options).subscribe({ next() { - expect(link.operation.getContext().someVar).toEqual( + expect(link.operation?.getContext().someVar).toEqual( options.context.someVar ); resolve(); diff --git a/src/__tests__/local-state/general.ts b/src/__tests__/local-state/general.ts index 30d31feea33..0d65993e821 100644 --- a/src/__tests__/local-state/general.ts +++ b/src/__tests__/local-state/general.ts @@ -1207,7 +1207,7 @@ describe("Combining client and server state/operations", () => { watchCount += 1; client.mutate({ mutation, - update(proxy, { data: { updateUser } }: { data: any }) { + update(proxy, { data: { updateUser } }) { proxy.writeQuery({ query: userQuery, data: { diff --git a/src/__tests__/local-state/resolvers.ts b/src/__tests__/local-state/resolvers.ts index c1052748841..b305a3ed7d8 100644 --- a/src/__tests__/local-state/resolvers.ts +++ b/src/__tests__/local-state/resolvers.ts @@ -11,7 +11,7 @@ import { WatchQueryOptions, } from "../../core"; -import { InMemoryCache } from "../../cache"; +import { InMemoryCache, isReference } from "../../cache"; import { Observable, Observer } from "../../utilities"; import { ApolloLink } from "../../link/core"; import { itAsync } from "../../testing"; @@ -747,10 +747,13 @@ describe("Writing cache data from resolvers", () => { }, }, }); - cache.modify({ + cache.modify<{ field: { field2: number } }>({ id: "Object:uniqueId", fields: { - field(value: { field2: number }) { + field(value) { + if (isReference(value)) { + fail("Should not be a reference"); + } expect(value.field2).toBe(1); return { ...value, field2: 2 }; }, diff --git a/src/__tests__/optimistic.ts b/src/__tests__/optimistic.ts index d8c20501821..4184a2f8d6d 100644 --- a/src/__tests__/optimistic.ts +++ b/src/__tests__/optimistic.ts @@ -235,7 +235,7 @@ describe("optimistic mutation results", () => { await promise; } catch (err) { expect(err).toBeInstanceOf(Error); - expect(err.message).toBe("forbidden (test error)"); + expect((err as Error).message).toBe("forbidden (test error)"); const dataInStore = (client.cache as InMemoryCache).extract(true); expect((dataInStore["TodoList5"] as any).todos.length).toBe(3); @@ -489,7 +489,7 @@ describe("optimistic mutation results", () => { await promise; } catch (err) { expect(err).toBeInstanceOf(Error); - expect(err.message).toBe("forbidden (test error)"); + expect((err as Error).message).toBe("forbidden (test error)"); const dataInStore = (client.cache as InMemoryCache).extract(true); expect((dataInStore["TodoList5"] as any).todos.length).toBe(3); @@ -2019,11 +2019,12 @@ describe("optimistic mutation results", () => { const wrapReject = ( fn: (...args: TArgs) => TResult ): typeof fn => { - return function () { + return function (this: unknown, ...args: TArgs) { try { - return fn.apply(this, arguments); + return fn.apply(this, args); } catch (e) { reject(e); + throw e; } }; }; diff --git a/src/__tests__/subscribeToMore.ts b/src/__tests__/subscribeToMore.ts index 2903dacdbbd..419b0b696d0 100644 --- a/src/__tests__/subscribeToMore.ts +++ b/src/__tests__/subscribeToMore.ts @@ -8,8 +8,10 @@ import { itAsync, mockSingleLink, mockObservableLink } from "../testing"; const isSub = (operation: Operation) => (operation.query as DocumentNode).definitions - .filter((x) => x.kind === "OperationDefinition") - .some((x: OperationDefinitionNode) => x.operation === "subscription"); + .filter( + (x): x is OperationDefinitionNode => x.kind === "OperationDefinition" + ) + .some((x) => x.operation === "subscription"); describe("subscribeToMore", () => { const query = gql` diff --git a/src/cache/core/types/Cache.ts b/src/cache/core/types/Cache.ts index 8628f272a19..58835e6aca5 100644 --- a/src/cache/core/types/Cache.ts +++ b/src/cache/core/types/Cache.ts @@ -93,7 +93,7 @@ export namespace Cache { this: TCache, watch: Cache.WatchOptions, diff: Cache.DiffResult, - lastDiff: Cache.DiffResult | undefined + lastDiff?: Cache.DiffResult | undefined ) => any; } diff --git a/src/cache/inmemory/__tests__/cache.ts b/src/cache/inmemory/__tests__/cache.ts index a7289cd2c64..edaa63fb4d4 100644 --- a/src/cache/inmemory/__tests__/cache.ts +++ b/src/cache/inmemory/__tests__/cache.ts @@ -4035,6 +4035,7 @@ describe("ReactiveVar and makeVar", () => { let broadcastCount = 0; cache["broadcastWatches"] = function () { ++broadcastCount; + // @ts-expect-error return broadcast.apply(this, arguments); }; diff --git a/src/cache/inmemory/__tests__/diffAgainstStore.ts b/src/cache/inmemory/__tests__/diffAgainstStore.ts index 5beef906247..0a315c60270 100644 --- a/src/cache/inmemory/__tests__/diffAgainstStore.ts +++ b/src/cache/inmemory/__tests__/diffAgainstStore.ts @@ -493,8 +493,8 @@ describe("diffing queries against the store", () => { }; const cache = new InMemoryCache({ - dataIdFromObject({ id }: { id: string }) { - return id; + dataIdFromObject(obj: any) { + return obj.id; }, }); @@ -841,7 +841,7 @@ describe("diffing queries against the store", () => { const writer = new StoreWriter( new InMemoryCache({ - dataIdFromObject: ({ id }: { id: string }) => id, + dataIdFromObject: (obj: any) => obj.id, }) ); @@ -1067,7 +1067,7 @@ describe("diffing queries against the store", () => { }); throw new Error("should have thrown"); } catch (e) { - expect(e.message).toEqual( + expect((e as Error).message).toEqual( "Missing selection set for object of type Message returned for query field messageList" ); } diff --git a/src/cache/inmemory/__tests__/readFromStore.ts b/src/cache/inmemory/__tests__/readFromStore.ts index 99472adc335..328336ec3ed 100644 --- a/src/cache/inmemory/__tests__/readFromStore.ts +++ b/src/cache/inmemory/__tests__/readFromStore.ts @@ -1904,7 +1904,7 @@ describe("reading from the store", () => { ); expect(value.__ref).toBe('Deity:{"name":"Zeus"}'); // Interim ruler Apollo takes over for real. - return toReference(apolloRulerResult.ruler); + return toReference(apolloRulerResult.ruler)!; }, }, }); diff --git a/src/cache/inmemory/__tests__/roundtrip.ts b/src/cache/inmemory/__tests__/roundtrip.ts index 6f04fabe5d7..5c6824cdc6e 100644 --- a/src/cache/inmemory/__tests__/roundtrip.ts +++ b/src/cache/inmemory/__tests__/roundtrip.ts @@ -61,7 +61,7 @@ function storeRoundtrip(query: DocumentNode, result: any, variables = {}) { (immutableResult as any).illegal = "this should not work"; throw new Error("unreached"); } catch (e) { - expect(e.message).not.toMatch(/unreached/); + expect((e as Error).message).not.toMatch(/unreached/); expect(e).toBeInstanceOf(TypeError); } assertDeeplyFrozen(immutableResult); diff --git a/src/cache/inmemory/__tests__/writeToStore.ts b/src/cache/inmemory/__tests__/writeToStore.ts index f1911b0a3c4..e00b21d9bba 100644 --- a/src/cache/inmemory/__tests__/writeToStore.ts +++ b/src/cache/inmemory/__tests__/writeToStore.ts @@ -25,9 +25,14 @@ import { defaultNormalizedCacheFactory, writeQueryToStore } from "./helpers"; import { InMemoryCache } from "../inMemoryCache"; import { TypedDocumentNode } from "../../../core"; import { extractFragmentContext } from "../helpers"; +import { KeyFieldsFunction } from "../policies"; +import { invariant } from "../../../utilities/globals"; import { spyOnConsole } from "../../../testing/internal"; -const getIdField = ({ id }: { id: string }) => id; +const getIdField: KeyFieldsFunction = ({ id }) => { + invariant(typeof id === "string", "id is not a string"); + return id; +}; describe("writing to the store", () => { const cache = new InMemoryCache({ @@ -1293,19 +1298,17 @@ describe("writing to the store", () => { } testData.forEach((data) => { - data.mutation.definitions.forEach( - (definition: OperationDefinitionNode) => { - if (isOperationDefinition(definition)) { - definition.selectionSet.selections.forEach((selection) => { - if (isField(selection)) { - expect( - storeKeyNameFromField(selection, data.variables) - ).toEqual(data.expected); - } - }); - } + data.mutation.definitions.forEach((definition) => { + if (isOperationDefinition(definition)) { + definition.selectionSet.selections.forEach((selection) => { + if (isField(selection)) { + expect(storeKeyNameFromField(selection, data.variables)).toEqual( + data.expected + ); + } + }); } - ); + }); }); }); @@ -1357,7 +1360,7 @@ describe("writing to the store", () => { return value.kind === "OperationDefinition"; } - mutation.definitions.map((def: OperationDefinitionNode) => { + mutation.definitions.map((def) => { if (isOperationDefinition(def)) { const writer = new StoreWriter( new InMemoryCache({ diff --git a/src/cache/inmemory/entityStore.ts b/src/cache/inmemory/entityStore.ts index ddb03b274da..a31f96db63a 100644 --- a/src/cache/inmemory/entityStore.ts +++ b/src/cache/inmemory/entityStore.ts @@ -593,7 +593,7 @@ class CacheGroup { // Used by the EntityStore#makeCacheKey method to compute cache keys // specific to this CacheGroup. - public keyMaker: Trie; + public keyMaker!: Trie; constructor( public readonly caching: boolean, @@ -800,7 +800,11 @@ class Layer extends EntityStore { public getStorage(): StorageType { let p: EntityStore = this.parent; while ((p as Layer).parent) p = (p as Layer).parent; - return p.getStorage.apply(p, arguments); + return p.getStorage.apply( + p, + // @ts-expect-error + arguments + ); } } @@ -823,20 +827,20 @@ class Stump extends Layer { return this; } - public merge() { + public merge(older: string | StoreObject, newer: string | StoreObject) { // We never want to write any data into the Stump, so we forward any merge // calls to the Root instead. Another option here would be to throw an // exception, but the toReference(object, true) function can sometimes // trigger Stump writes (which used to be Root writes, before the Stump // concept was introduced). - return this.parent.merge.apply(this.parent, arguments); + return this.parent.merge(older, newer); } } function storeObjectReconciler( existingObject: StoreObject, incomingObject: StoreObject, - property: string + property: string | number ): StoreValue { const existingValue = existingObject[property]; const incomingValue = incomingObject[property]; diff --git a/src/cache/inmemory/fixPolyfills.native.ts b/src/cache/inmemory/fixPolyfills.native.ts index d2302429c74..4b75824841a 100644 --- a/src/cache/inmemory/fixPolyfills.native.ts +++ b/src/cache/inmemory/fixPolyfills.native.ts @@ -33,10 +33,10 @@ try { // https://github.com/apollographql/react-apollo/issues/2442#issuecomment-426489517 testMap.set(frozen, frozen).delete(frozen); } catch { - const wrap = (method: (obj: T) => T): typeof method => { + const wrap = (obj: T) => T>(method: M): M => { return ( method && - ((obj) => { + (((obj) => { try { // If .set succeeds, also call .delete to avoid leaking memory. testMap.set(obj, obj).delete(obj); @@ -45,7 +45,7 @@ try { // by this return-from-finally statement: return method.call(Object, obj); } - }) + }) as M) ); }; Object.freeze = wrap(Object.freeze); diff --git a/src/cache/inmemory/fragmentRegistry.ts b/src/cache/inmemory/fragmentRegistry.ts index e868122d1d2..0832e6a7934 100644 --- a/src/cache/inmemory/fragmentRegistry.ts +++ b/src/cache/inmemory/fragmentRegistry.ts @@ -6,6 +6,7 @@ import type { } from "graphql"; import { visit } from "graphql"; +import type { OptimisticWrapperFunction } from "optimism"; import { wrap } from "optimism"; import type { FragmentMap } from "../../utilities/index.js"; @@ -29,24 +30,22 @@ export function createFragmentRegistry( return new FragmentRegistry(...fragments); } -const { forEach: arrayLikeForEach } = Array.prototype; - class FragmentRegistry implements FragmentRegistryAPI { private registry: FragmentMap = Object.create(null); - // Call static method FragmentRegistry.from(...) instead of invoking the + // Call `createFragmentRegistry` instead of invoking the // FragmentRegistry constructor directly. This reserves the constructor for // future configuration of the FragmentRegistry. constructor(...fragments: DocumentNode[]) { this.resetCaches(); if (fragments.length) { - this.register.apply(this, fragments); + this.register(...fragments); } } - public register(): this { + public register(...fragments: DocumentNode[]): this { const definitions = new Map(); - arrayLikeForEach.call(arguments, (doc: DocumentNode) => { + fragments.forEach((doc: DocumentNode) => { getFragmentDefinitions(doc).forEach((node) => { definitions.set(node.name.value, node); }); @@ -66,27 +65,15 @@ class FragmentRegistry implements FragmentRegistryAPI { private invalidate(name: string) {} public resetCaches() { - this.invalidate = (this.lookup = this.cacheUnaryMethod("lookup")).dirty; // This dirty function is bound to the wrapped lookup method. - this.transform = this.cacheUnaryMethod("transform"); - this.findFragmentSpreads = this.cacheUnaryMethod("findFragmentSpreads"); + this.invalidate = (this.lookup = this.cacheUnaryMethod(this.lookup)).dirty; // This dirty function is bound to the wrapped lookup method. + this.transform = this.cacheUnaryMethod(this.transform); + this.findFragmentSpreads = this.cacheUnaryMethod(this.findFragmentSpreads); } - private cacheUnaryMethod< - TName extends keyof Pick< - FragmentRegistry, - "lookup" | "transform" | "findFragmentSpreads" - >, - >(name: TName) { - const registry = this; - const originalMethod = FragmentRegistry.prototype[name]; - return wrap( - function () { - return originalMethod.apply(registry, arguments); - }, - { - makeCacheKey: (arg) => arg, - } - ); + private cacheUnaryMethod any>(originalMethod: F) { + return wrap, ReturnType>(originalMethod.bind(this), { + makeCacheKey: (arg) => arg, + }) as OptimisticWrapperFunction, ReturnType> & F; } public lookup(fragmentName: string): FragmentDefinitionNode | null { diff --git a/src/cache/inmemory/inMemoryCache.ts b/src/cache/inmemory/inMemoryCache.ts index 2dac460bf54..ff7e9cd8b91 100644 --- a/src/cache/inmemory/inMemoryCache.ts +++ b/src/cache/inmemory/inMemoryCache.ts @@ -33,18 +33,18 @@ type BroadcastOptions = Pick< >; export class InMemoryCache extends ApolloCache { - private data: EntityStore; - private optimisticData: EntityStore; + private data!: EntityStore; + private optimisticData!: EntityStore; protected config: InMemoryCacheConfig; private watches = new Set(); private addTypename: boolean; - private storeReader: StoreReader; - private storeWriter: StoreWriter; + private storeReader!: StoreReader; + private storeWriter!: StoreWriter; private addTypenameTransform = new DocumentTransform(addTypenameToDocument); - private maybeBroadcastWatch: OptimisticWrapperFunction< + private maybeBroadcastWatch!: OptimisticWrapperFunction< [Cache.WatchOptions, BroadcastOptions?], any, [Cache.WatchOptions] diff --git a/src/cache/inmemory/readFromStore.ts b/src/cache/inmemory/readFromStore.ts index 9a9ddc1498c..34a81f07c93 100644 --- a/src/cache/inmemory/readFromStore.ts +++ b/src/cache/inmemory/readFromStore.ts @@ -535,7 +535,7 @@ function firstMissing(tree: MissingTree): string | undefined { return value; }); } catch (result) { - return result; + return result as string; } } diff --git a/src/core/ApolloClient.ts b/src/core/ApolloClient.ts index 12b9e7e0e0e..5feb29f792d 100644 --- a/src/core/ApolloClient.ts +++ b/src/core/ApolloClient.ts @@ -86,7 +86,7 @@ export class ApolloClient implements DataProxy { public readonly typeDefs: ApolloClientOptions["typeDefs"]; private queryManager: QueryManager; - private devToolsHookCb: Function; + private devToolsHookCb?: Function; private resetStoreCallbacks: Array<() => Promise> = []; private clearStoreCallbacks: Array<() => Promise> = []; private localState: LocalState; @@ -592,7 +592,9 @@ export class ApolloClient implements DataProxy { >( options: RefetchQueriesOptions ): RefetchQueriesResult { - const map = this.queryManager.refetchQueries(options); + const map = this.queryManager.refetchQueries( + options as RefetchQueriesOptions, TResult> + ); const queries: ObservableQuery[] = []; const results: InternalRefetchQueriesResult[] = []; diff --git a/src/core/LocalState.ts b/src/core/LocalState.ts index 6f0aaf61f08..4b68b787c2a 100644 --- a/src/core/LocalState.ts +++ b/src/core/LocalState.ts @@ -75,9 +75,9 @@ export type LocalStateOptions = { export class LocalState { private cache: ApolloCache; - private client: ApolloClient; + private client?: ApolloClient; private resolvers?: Resolvers; - private fragmentMatcher: FragmentMatcher; + private fragmentMatcher?: FragmentMatcher; private selectionsToResolveCache = new WeakMap< ExecutableDefinitionNode, Set @@ -162,7 +162,7 @@ export class LocalState { this.fragmentMatcher = fragmentMatcher; } - public getFragmentMatcher(): FragmentMatcher { + public getFragmentMatcher(): FragmentMatcher | undefined { return this.fragmentMatcher; } @@ -197,11 +197,11 @@ export class LocalState { // To support `@client @export(as: "someVar")` syntax, we'll first resolve // @client @export fields locally, then pass the resolved values back to be // used alongside the original operation variables. - public async addExportedVariables( + public async addExportedVariables( document: DocumentNode, - variables: OperationVariables = {}, + variables: TVars = {} as TVars, context = {} - ) { + ): /* returns at least the variables that were passed in */ Promise { if (document) { return this.resolveDocument( document, diff --git a/src/core/ObservableQuery.ts b/src/core/ObservableQuery.ts index 57f0867276f..bda85a543a7 100644 --- a/src/core/ObservableQuery.ts +++ b/src/core/ObservableQuery.ts @@ -35,6 +35,7 @@ import type { QueryInfo } from "./QueryInfo.js"; import type { MissingFieldError } from "../cache/index.js"; import type { MissingTree } from "../cache/core/types/common.js"; import { equalByQuery } from "./equalByQuery.js"; +import type { TODO } from "../utilities/types/TODO.js"; const { assign, hasOwnProperty } = Object; @@ -924,8 +925,9 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`, public reobserve( newOptions?: Partial>, newNetworkStatus?: NetworkStatus - ) { - return this.reobserveAsConcast(newOptions, newNetworkStatus).promise; + ): Promise> { + return this.reobserveAsConcast(newOptions, newNetworkStatus) + .promise as TODO; } public resubscribeAfterError( @@ -1048,14 +1050,18 @@ export function reobserveCacheFirst( fetchPolicy: "cache-first", // Use a temporary nextFetchPolicy function that replaces itself with the // previous nextFetchPolicy value and returns the original fetchPolicy. - nextFetchPolicy(this: WatchQueryOptions) { + nextFetchPolicy( + this: WatchQueryOptions, + currentFetchPolicy: WatchQueryFetchPolicy, + context: NextFetchPolicyContext + ) { // Replace this nextFetchPolicy function in the options object with the // original this.options.nextFetchPolicy value. this.nextFetchPolicy = nextFetchPolicy; // If the original nextFetchPolicy value was a function, give it a // chance to decide what happens here. - if (typeof nextFetchPolicy === "function") { - return nextFetchPolicy.apply(this, arguments); + if (typeof this.nextFetchPolicy === "function") { + return this.nextFetchPolicy(currentFetchPolicy, context); } // Otherwise go back to the original this.options.fetchPolicy. return fetchPolicy!; diff --git a/src/core/QueryInfo.ts b/src/core/QueryInfo.ts index 1b6f17acc5a..cdf0d358ceb 100644 --- a/src/core/QueryInfo.ts +++ b/src/core/QueryInfo.ts @@ -49,6 +49,7 @@ function wrapDestructiveCacheMethod( // that matters in any conceivable practical scenario. (destructiveMethodCounts.get(cache)! + 1) % 1e15 ); + // @ts-expect-error this is just too generic to be typed correctly return original.apply(this, arguments); }; } @@ -111,7 +112,7 @@ export class QueryInfo { // NetworkStatus.loading, but also possibly fetchMore, poll, refetch, // or setVariables. networkStatus?: NetworkStatus; - observableQuery?: ObservableQuery; + observableQuery?: ObservableQuery; lastRequestId?: number; }): this { let networkStatus = query.networkStatus || NetworkStatus.loading; @@ -212,10 +213,10 @@ export class QueryInfo { } } - public readonly observableQuery: ObservableQuery | null = null; + public readonly observableQuery: ObservableQuery | null = null; private oqListener?: QueryListener; - setObservableQuery(oq: ObservableQuery | null) { + setObservableQuery(oq: ObservableQuery | null) { if (oq === this.observableQuery) return; if (this.oqListener) { diff --git a/src/core/QueryManager.ts b/src/core/QueryManager.ts index f57d7afda6c..23ee9320400 100644 --- a/src/core/QueryManager.ts +++ b/src/core/QueryManager.ts @@ -74,6 +74,7 @@ import { import type { ApolloErrorOptions } from "../errors/index.js"; import { PROTOCOL_ERRORS_SYMBOL } from "../errors/index.js"; import { print } from "../utilities/index.js"; +import type { TODO } from "../utilities/types/TODO.js"; const { hasOwnProperty } = Object.prototype; @@ -479,7 +480,7 @@ export class QueryManager { const results: any[] = []; this.refetchQueries({ - updateCache: (cache: TCache) => { + updateCache: (cache) => { if (!skipCache) { cacheWrites.forEach((write) => cache.write(write)); } @@ -526,7 +527,7 @@ export class QueryManager { // either a SingleExecutionResult or the final ExecutionPatchResult, // call the update function. if (isFinalResult) { - update(cache, result, { + update(cache as TCache, result, { context: mutation.context, variables: mutation.variables, }); @@ -617,7 +618,7 @@ export class QueryManager { networkStatus?: NetworkStatus ): Promise> { return this.fetchConcastWithInfo(queryId, options, networkStatus).concast - .promise; + .promise as TODO; } public getQueryStore() { diff --git a/src/core/__tests__/ObservableQuery.ts b/src/core/__tests__/ObservableQuery.ts index 3104be8ea96..add7b8a61ee 100644 --- a/src/core/__tests__/ObservableQuery.ts +++ b/src/core/__tests__/ObservableQuery.ts @@ -46,7 +46,8 @@ export const mockFetchQuery = (queryManager: QueryManager) => { >( original: T ) => - jest.fn, Parameters>(function () { + jest.fn, Parameters>(function (): ReturnType { + // @ts-expect-error return original.apply(queryManager, arguments); }); @@ -2740,7 +2741,7 @@ describe("ObservableQuery", () => { throw new Error("not reached"); } catch (error) { expect(error).toBeInstanceOf(TypeError); - expect(error.message).toMatch( + expect((error as Error).message).toMatch( /Cannot assign to read only property 'value'/ ); } diff --git a/src/core/__tests__/QueryManager/index.ts b/src/core/__tests__/QueryManager/index.ts index 77fd0fe6dbd..11f92046721 100644 --- a/src/core/__tests__/QueryManager/index.ts +++ b/src/core/__tests__/QueryManager/index.ts @@ -1610,7 +1610,7 @@ describe("QueryManager", () => { }); }); - const getIdField = ({ id }: { id: string }) => id; + const getIdField = (obj: any) => obj.id; itAsync( "runs a mutation with object parameters and puts the result in the store", diff --git a/src/link/batch-http/__tests__/batchHttpLink.ts b/src/link/batch-http/__tests__/batchHttpLink.ts index 525636addb6..544f44c304f 100644 --- a/src/link/batch-http/__tests__/batchHttpLink.ts +++ b/src/link/batch-http/__tests__/batchHttpLink.ts @@ -35,10 +35,11 @@ function makeCallback( ) { return function () { try { + // @ts-expect-error callback.apply(this, arguments); resolve(); } catch (error) { - reject(error); + reject(error as Error); } } as typeof callback; } @@ -472,7 +473,7 @@ describe("SharedHttpTest", () => { after(); } catch (e) { - reject(e); + reject(e as Error); } }, }); diff --git a/src/link/batch/__tests__/batchLink.ts b/src/link/batch/__tests__/batchLink.ts index 1a564fd2796..e5930924c27 100644 --- a/src/link/batch/__tests__/batchLink.ts +++ b/src/link/batch/__tests__/batchLink.ts @@ -64,6 +64,7 @@ function terminatingCheck( ) { return function () { try { + // @ts-expect-error callback.apply(this, arguments); resolve(); } catch (error) { diff --git a/src/link/error/index.ts b/src/link/error/index.ts index ec5d6dffba9..7122ff792e8 100644 --- a/src/link/error/index.ts +++ b/src/link/error/index.ts @@ -84,7 +84,7 @@ export function onError(errorHandler: ErrorHandler): ApolloLink { }, }); } catch (e) { - errorHandler({ networkError: e, operation, forward }); + errorHandler({ networkError: e as Error, operation, forward }); observer.error(e); } diff --git a/src/link/http/HttpLink.ts b/src/link/http/HttpLink.ts index 06479e050f2..c59c04566cf 100644 --- a/src/link/http/HttpLink.ts +++ b/src/link/http/HttpLink.ts @@ -1,10 +1,8 @@ -import type { RequestHandler } from "../core/index.js"; import { ApolloLink } from "../core/index.js"; import type { HttpOptions } from "./selectHttpOptionsAndBody.js"; import { createHttpLink } from "./createHttpLink.js"; export class HttpLink extends ApolloLink { - public requester: RequestHandler; constructor(public options: HttpOptions = {}) { super(createHttpLink(options).request); } diff --git a/src/link/http/__tests__/HttpLink.ts b/src/link/http/__tests__/HttpLink.ts index 4523c4d0fcb..b2ce5308cfd 100644 --- a/src/link/http/__tests__/HttpLink.ts +++ b/src/link/http/__tests__/HttpLink.ts @@ -92,10 +92,11 @@ function makeCallback( ) { return function () { try { + // @ts-expect-error callback.apply(this, arguments); resolve(); } catch (error) { - reject(error); + reject(error as Error); } } as typeof callback; } @@ -1202,7 +1203,7 @@ describe("HttpLink", () => { reject("warning wasn't called"); } catch (e) { makeCallback(resolve, reject, () => - expect(e.message).toMatch(/has not been found globally/) + expect((e as Error).message).toMatch(/has not been found globally/) )(); } }); @@ -1214,7 +1215,7 @@ describe("HttpLink", () => { reject("warning wasn't called"); } catch (e) { makeCallback(resolve, reject, () => - expect(e.message).toMatch(/has not been found globally/) + expect((e as Error).message).toMatch(/has not been found globally/) )(); } }); diff --git a/src/link/http/__tests__/responseIterator.ts b/src/link/http/__tests__/responseIterator.ts index 74ffa328c60..3800a257a8d 100644 --- a/src/link/http/__tests__/responseIterator.ts +++ b/src/link/http/__tests__/responseIterator.ts @@ -17,10 +17,11 @@ function makeCallback( ) { return function () { try { + // @ts-expect-error callback.apply(this, arguments); resolve(); } catch (error) { - reject(error); + reject(error as Error); } } as typeof callback; } diff --git a/src/link/http/iterators/reader.ts b/src/link/http/iterators/reader.ts index 3a81e37cf2a..d9feac48d07 100644 --- a/src/link/http/iterators/reader.ts +++ b/src/link/http/iterators/reader.ts @@ -6,7 +6,7 @@ import { canUseAsyncIteratorSymbol } from "../../../utilities/index.js"; interface ReaderIterator { - next(): Promise>; + next(): Promise>; [Symbol.asyncIterator]?(): AsyncIterator; } @@ -15,12 +15,20 @@ export default function readerIterator( ): AsyncIterableIterator { const iterator: ReaderIterator = { next() { - return reader.read(); + return reader.read() as Promise< + | ReadableStreamReadValueResult + // DoneResult has `value` optional, which doesn't comply with an + // `IteratorResult`, so we assert it to `T | undefined` instead + | Required> + >; }, }; if (canUseAsyncIteratorSymbol) { - iterator[Symbol.asyncIterator] = function (): AsyncIterator { + iterator[Symbol.asyncIterator] = function (): AsyncIterator< + T, + T | undefined + > { return this; }; } diff --git a/src/link/http/serializeFetchParameter.ts b/src/link/http/serializeFetchParameter.ts index 4ad2b3db2cd..5a08fe67269 100644 --- a/src/link/http/serializeFetchParameter.ts +++ b/src/link/http/serializeFetchParameter.ts @@ -9,7 +9,7 @@ export const serializeFetchParameter = (p: any, label: string) => { let serialized; try { serialized = JSON.stringify(p); - } catch (e) { + } catch (e: any) { const parseError = newInvariantError( `Network request failed. %s is not serializable: %s`, label, diff --git a/src/link/persisted-queries/__tests__/persisted-queries.test.ts b/src/link/persisted-queries/__tests__/persisted-queries.test.ts index 37fc4c9c476..ea8b56e660a 100644 --- a/src/link/persisted-queries/__tests__/persisted-queries.test.ts +++ b/src/link/persisted-queries/__tests__/persisted-queries.test.ts @@ -219,7 +219,7 @@ describe("happy path", () => { reject("should have thrown an error"); } catch (error) { expect( - error.message.indexOf( + (error as Error).message.indexOf( 'Missing/invalid "sha256" or "generateHash" function' ) ).toBe(0); @@ -238,7 +238,7 @@ describe("happy path", () => { reject("should have thrown an error"); } catch (error) { expect( - error.message.indexOf( + (error as Error).message.indexOf( 'Missing/invalid "sha256" or "generateHash" function' ) ).toBe(0); @@ -569,6 +569,7 @@ describe("failure path", () => { status, }); } + // @ts-expect-error return global.fetch.apply(null, args); }; const link = createPersistedQuery({ sha256 }).concat( @@ -623,6 +624,7 @@ describe("failure path", () => { status, }); } + // @ts-expect-error return global.fetch.apply(null, args); }; const link = createPersistedQuery({ sha256 }).concat( @@ -662,6 +664,7 @@ describe("failure path", () => { status, }); } + // @ts-expect-error return global.fetch.apply(null, args); }; diff --git a/src/react/cache/QueryReference.ts b/src/react/cache/QueryReference.ts index f1ad5732bac..5b2fc14c643 100644 --- a/src/react/cache/QueryReference.ts +++ b/src/react/cache/QueryReference.ts @@ -73,7 +73,7 @@ export class InternalQueryReference { private subscription: ObservableSubscription; private listeners = new Set>(); - private autoDisposeTimeoutId: NodeJS.Timeout; + private autoDisposeTimeoutId?: NodeJS.Timeout; private status: "idle" | "loading" = "loading"; private resolve: ((result: ApolloQueryResult) => void) | undefined; diff --git a/src/react/cache/SuspenseCache.ts b/src/react/cache/SuspenseCache.ts index e5f8036ecea..af883c0a52a 100644 --- a/src/react/cache/SuspenseCache.ts +++ b/src/react/cache/SuspenseCache.ts @@ -32,7 +32,9 @@ export class SuspenseCache { cacheKey: CacheKey, createObservable: () => ObservableQuery ) { - const ref = this.queryRefs.lookupArray(cacheKey); + const ref = this.queryRefs.lookupArray(cacheKey) as { + current?: InternalQueryReference; + }; if (!ref.current) { ref.current = new InternalQueryReference(createObservable(), { @@ -44,6 +46,6 @@ export class SuspenseCache { }); } - return ref.current as InternalQueryReference; + return ref.current; } } diff --git a/src/react/hoc/__tests__/fragments.test.tsx b/src/react/hoc/__tests__/fragments.test.tsx index 1597a4b7092..741e5e2f8f7 100644 --- a/src/react/hoc/__tests__/fragments.test.tsx +++ b/src/react/hoc/__tests__/fragments.test.tsx @@ -55,7 +55,7 @@ describe("fragments", () => { ); throw new Error(); } catch (e) { - expect(e.name).toMatch(/Invariant Violation/); + expect((e as Error).name).toMatch(/Invariant Violation/); } }); diff --git a/src/react/hoc/__tests__/queries/errors.test.tsx b/src/react/hoc/__tests__/queries/errors.test.tsx index 449e3c46c67..dfe92de05ce 100644 --- a/src/react/hoc/__tests__/queries/errors.test.tsx +++ b/src/react/hoc/__tests__/queries/errors.test.tsx @@ -105,7 +105,7 @@ describe("[queries] errors", () => { try { unmount(); - } catch (e) { + } catch (e: any) { throw new Error(e); } }); @@ -220,6 +220,7 @@ describe("[queries] errors", () => { "setVar", 1 )( + // @ts-expect-error graphql(query)( class extends React.Component> { componentDidUpdate() { diff --git a/src/react/hoc/__tests__/queries/updateQuery.test.tsx b/src/react/hoc/__tests__/queries/updateQuery.test.tsx index 0d3056b862e..b11de81c326 100644 --- a/src/react/hoc/__tests__/queries/updateQuery.test.tsx +++ b/src/react/hoc/__tests__/queries/updateQuery.test.tsx @@ -143,7 +143,7 @@ describe("[queries] updateQuery", () => { ).toBeTruthy(); try { this.props.data!.updateQuery((p) => p); - } catch (e) { + } catch (e: any) { // TODO: branch never hit in test expect(e.toString()).toMatch( /ObservableQuery with this id doesn't exist:/ diff --git a/src/react/hoc/__tests__/ssr/getDataFromTree.test.tsx b/src/react/hoc/__tests__/ssr/getDataFromTree.test.tsx index b4a0ab6fc6c..13172453f78 100644 --- a/src/react/hoc/__tests__/ssr/getDataFromTree.test.tsx +++ b/src/react/hoc/__tests__/ssr/getDataFromTree.test.tsx @@ -945,6 +945,7 @@ describe("SSR", () => { ); + // @ts-expect-error const WrappedElement = withQuery(withMutation(Element)); const app = ( diff --git a/src/react/hoc/mutation-hoc.tsx b/src/react/hoc/mutation-hoc.tsx index a0098a0f290..7705c1eeda4 100644 --- a/src/react/hoc/mutation-hoc.tsx +++ b/src/react/hoc/mutation-hoc.tsx @@ -86,6 +86,7 @@ export function withMutation< return ( + {/* @ts-expect-error */} {( mutate: MutationFunction, { data, ...r }: MutationResult diff --git a/src/react/hooks/useBackgroundQuery.ts b/src/react/hooks/useBackgroundQuery.ts index 8e49114e7aa..cb6cf125113 100644 --- a/src/react/hooks/useBackgroundQuery.ts +++ b/src/react/hooks/useBackgroundQuery.ts @@ -1,8 +1,10 @@ import * as React from "react"; import type { DocumentNode, + FetchMoreQueryOptions, OperationVariables, TypedDocumentNode, + WatchQueryOptions, } from "../../core/index.js"; import { useApolloClient } from "./useApolloClient.js"; import { wrapQueryRef } from "../cache/QueryReference.js"; @@ -197,7 +199,7 @@ export function useBackgroundQuery< ]; const queryRef = suspenseCache.getQueryRef(cacheKey, () => - client.watchQuery(watchQueryOptions) + client.watchQuery(watchQueryOptions as WatchQueryOptions) ); const [promiseCache, setPromiseCache] = React.useState( @@ -213,7 +215,7 @@ export function useBackgroundQuery< const fetchMore: FetchMoreFunction = React.useCallback( (options) => { - const promise = queryRef.fetchMore(options); + const promise = queryRef.fetchMore(options as FetchMoreQueryOptions); setPromiseCache((promiseCache) => new Map(promiseCache).set(queryRef.key, queryRef.promise) diff --git a/src/react/hooks/useLazyQuery.ts b/src/react/hooks/useLazyQuery.ts index 535b9b4ceb2..51cddd464b1 100644 --- a/src/react/hooks/useLazyQuery.ts +++ b/src/react/hooks/useLazyQuery.ts @@ -75,6 +75,7 @@ export function useLazyQuery< // Only the first time populating execOptionsRef.current matters here. internalState.forceUpdateState(); } + // @ts-expect-error this is just too generic to type return method.apply(this, arguments); }; } diff --git a/src/react/hooks/useMutation.ts b/src/react/hooks/useMutation.ts index 2eff46ee272..2122067b2e2 100644 --- a/src/react/hooks/useMutation.ts +++ b/src/react/hooks/useMutation.ts @@ -12,6 +12,7 @@ import type { import type { ApolloCache, DefaultContext, + MutationOptions, OperationVariables, } from "../../core/index.js"; import { mergeOptions } from "../../utilities/index.js"; @@ -87,10 +88,10 @@ export function useMutation< } const mutationId = ++ref.current.mutationId; - const clientOptions = mergeOptions(baseOptions, executeOptions as any); + const clientOptions = mergeOptions(baseOptions, executeOptions); return client - .mutate(clientOptions) + .mutate(clientOptions as MutationOptions) .then((response) => { const { data, errors } = response; const error = @@ -102,7 +103,10 @@ export function useMutation< executeOptions.onError || ref.current.options?.onError; if (error && onError) { - onError(error, clientOptions); + onError( + error, + clientOptions as MutationOptions + ); } if ( @@ -126,7 +130,10 @@ export function useMutation< executeOptions.onCompleted || ref.current.options?.onCompleted; if (!error) { - onCompleted?.(response.data!, clientOptions); + onCompleted?.( + response.data!, + clientOptions as MutationOptions + ); } return response; @@ -150,7 +157,10 @@ export function useMutation< executeOptions.onError || ref.current.options?.onError; if (onError) { - onError(error, clientOptions); + onError( + error, + clientOptions as MutationOptions + ); // TODO(brian): why are we returning this here??? return { data: void 0, errors: error }; diff --git a/src/react/hooks/useQuery.ts b/src/react/hooks/useQuery.ts index 33b127f62e6..d8509b52a03 100644 --- a/src/react/hooks/useQuery.ts +++ b/src/react/hooks/useQuery.ts @@ -271,8 +271,8 @@ class InternalState { // useQuery method, so we can safely use these members in other/later methods // without worrying they might be uninitialized. private renderPromises: ApolloContextValue["renderPromises"]; - private queryHookOptions: QueryHookOptions; - private watchQueryOptions: WatchQueryOptions; + private queryHookOptions!: QueryHookOptions; + private watchQueryOptions!: WatchQueryOptions; private useOptions(options: QueryHookOptions) { const watchQueryOptions = this.createWatchQueryOptions( @@ -461,8 +461,8 @@ class InternalState { private onCompleted(data: TData) {} private onError(error: ApolloError) {} - private observable: ObservableQuery; - private obsQueryFields: Omit< + private observable!: ObservableQuery; + private obsQueryFields!: Omit< ObservableQueryFields, "variables" >; diff --git a/src/react/hooks/useSuspenseQuery.ts b/src/react/hooks/useSuspenseQuery.ts index 1139b3a4984..eb4ca517963 100644 --- a/src/react/hooks/useSuspenseQuery.ts +++ b/src/react/hooks/useSuspenseQuery.ts @@ -178,7 +178,11 @@ export function useSuspenseQuery< ): UseSuspenseQueryResult { const client = useApolloClient(options.client); const suspenseCache = getSuspenseCache(client); - const watchQueryOptions = useWatchQueryOptions({ client, query, options }); + const watchQueryOptions = useWatchQueryOptions({ + client, + query, + options, + }); const { fetchPolicy, variables } = watchQueryOptions; const { queryKey = [] } = options; @@ -236,8 +240,8 @@ export function useSuspenseQuery< const result = fetchPolicy === "standby" ? skipResult : __use(promise); - const fetchMore: FetchMoreFunction = React.useCallback( - (options) => { + const fetchMore = React.useCallback( + ((options) => { const promise = queryRef.fetchMore(options); setPromiseCache((previousPromiseCache) => @@ -245,7 +249,10 @@ export function useSuspenseQuery< ); return promise; - }, + }) satisfies FetchMoreFunction< + unknown, + OperationVariables + > as FetchMoreFunction, [queryRef] ); @@ -262,13 +269,17 @@ export function useSuspenseQuery< [queryRef] ); - const subscribeToMore: SubscribeToMoreFunction = - React.useCallback( - (options) => queryRef.observable.subscribeToMore(options), - [queryRef] - ); + const subscribeToMore: SubscribeToMoreFunction< + TData | undefined, + TVariables + > = React.useCallback( + (options) => queryRef.observable.subscribeToMore(options), + [queryRef] + ); - return React.useMemo(() => { + return React.useMemo< + UseSuspenseQueryResult + >(() => { return { client, data: result.data, diff --git a/src/testing/core/itAsync.ts b/src/testing/core/itAsync.ts index 80fffe8f181..fc664cbac07 100644 --- a/src/testing/core/itAsync.ts +++ b/src/testing/core/itAsync.ts @@ -9,7 +9,7 @@ function wrap(key?: "only" | "skip" | "todo") { ) => (key ? it[key] : it)( message, - function () { + function (this: unknown) { return new Promise((resolve, reject) => callback.call(this, resolve, reject) ); @@ -21,7 +21,7 @@ function wrap(key?: "only" | "skip" | "todo") { const wrappedIt = wrap(); export const itAsync = Object.assign( - function (...args: Parameters) { + function (this: unknown, ...args: Parameters) { return wrappedIt.apply(this, args); }, { diff --git a/src/testing/core/mocking/mockLink.ts b/src/testing/core/mocking/mockLink.ts index e02d8aaf794..0c64363760c 100644 --- a/src/testing/core/mocking/mockLink.ts +++ b/src/testing/core/mocking/mockLink.ts @@ -45,7 +45,7 @@ function requestToKey(request: GraphQLRequest, addTypename: Boolean): string { } export class MockLink extends ApolloLink { - public operation: Operation; + public operation!: Operation; public addTypename: Boolean = true; public showWarnings: boolean = true; private mockedResponsesByKey: { [key: string]: MockedResponse[] } = {}; diff --git a/src/testing/core/mocking/mockSubscriptionLink.ts b/src/testing/core/mocking/mockSubscriptionLink.ts index 93e48d5ddb4..b91c86e8b68 100644 --- a/src/testing/core/mocking/mockSubscriptionLink.ts +++ b/src/testing/core/mocking/mockSubscriptionLink.ts @@ -15,7 +15,7 @@ export interface MockedSubscriptionResult { export class MockSubscriptionLink extends ApolloLink { public unsubscribers: any[] = []; public setups: any[] = []; - public operation: Operation; + public operation?: Operation; private observers: any[] = []; diff --git a/src/testing/core/observableToPromise.ts b/src/testing/core/observableToPromise.ts index 4d8415d4838..004a013593c 100644 --- a/src/testing/core/observableToPromise.ts +++ b/src/testing/core/observableToPromise.ts @@ -11,7 +11,7 @@ import type { ObservableSubscription } from "../../utilities/index.js"; * @param errorCallbacks an expected set of errors */ export type Options = { - observable: ObservableQuery; + observable: ObservableQuery; shouldResolve?: boolean; wait?: number; errorCallbacks?: ((error: Error) => any)[]; diff --git a/src/testing/core/withConsoleSpy.ts b/src/testing/core/withConsoleSpy.ts index c5c425e6e33..01626d7f5f9 100644 --- a/src/testing/core/withConsoleSpy.ts +++ b/src/testing/core/withConsoleSpy.ts @@ -2,8 +2,7 @@ function wrapTestFunction( fn: (...args: any[]) => any, consoleMethodName: "log" | "warn" | "error" ) { - return function () { - const args = arguments; + return function (this: any, ...args: any[]) { const spy = jest.spyOn(console, consoleMethodName); spy.mockImplementation(() => {}); return new Promise((resolve) => { diff --git a/src/testing/internal/profile/profile.tsx b/src/testing/internal/profile/profile.tsx index 12527844566..f4abb64af0e 100644 --- a/src/testing/internal/profile/profile.tsx +++ b/src/testing/internal/profile/profile.tsx @@ -203,7 +203,7 @@ export function profile< return render; }, async takeRender(options: NextRenderOptions = {}) { - let error: { message?: string } | undefined = undefined; + let error: unknown = undefined; try { return await Profiled.peekRender({ [_stackTrace]: captureStackTrace(Profiled.takeRender), diff --git a/src/testing/matchers/ProfiledComponent.ts b/src/testing/matchers/ProfiledComponent.ts index c733d50e241..469cfe00995 100644 --- a/src/testing/matchers/ProfiledComponent.ts +++ b/src/testing/matchers/ProfiledComponent.ts @@ -6,10 +6,10 @@ import type { ProfiledHook, } from "../internal/index.js"; export const toRerender: MatcherFunction<[options?: NextRenderOptions]> = - async function ( - _profiled: ProfiledComponent | ProfiledHook, - options?: NextRenderOptions - ) { + async function (actual, options) { + const _profiled = actual as + | ProfiledComponent + | ProfiledHook; const profiled = "ProfiledComponent" in _profiled ? _profiled.ProfiledComponent @@ -42,11 +42,10 @@ const failed = {}; export const toRenderExactlyTimes: MatcherFunction< [times: number, options?: NextRenderOptions] -> = async function ( - _profiled: ProfiledComponent | ProfiledHook, - times: number, - optionsPerRender?: NextRenderOptions -) { +> = async function (actual, times, optionsPerRender) { + const _profiled = actual as + | ProfiledComponent + | ProfiledHook; const profiled = "ProfiledComponent" in _profiled ? _profiled.ProfiledComponent : _profiled; const options = { timeout: 100, ...optionsPerRender }; diff --git a/src/tsconfig.json b/src/tsconfig.json new file mode 100644 index 00000000000..321f038a735 --- /dev/null +++ b/src/tsconfig.json @@ -0,0 +1,14 @@ +// `tsconfig.json` for the editor only +// this config includes additional files (e.g. tests) that +// we don't want to see hooked up to the main build +// it can also add a few more types for that purpose +{ + "compilerOptions": { + "noEmit": true, + "lib": ["es2015", "esnext.asynciterable", "dom"], + "types": ["jest", "node", "./testing/matchers/index.d.ts"] + }, + "extends": "../tsconfig.json", + "include": ["./**/*.ts", "./**/*.tsx"], + "exclude": [] +} diff --git a/src/utilities/common/__tests__/mergeDeep.ts b/src/utilities/common/__tests__/mergeDeep.ts index fbf4ec16eb1..fcdc680e720 100644 --- a/src/utilities/common/__tests__/mergeDeep.ts +++ b/src/utilities/common/__tests__/mergeDeep.ts @@ -146,7 +146,7 @@ describe("mergeDeep", function () { }); it("supports custom reconciler functions", function () { - const merger = new DeepMerger((target, source, key) => { + const merger = new DeepMerger(function (target, source, key) { const targetValue = target[key]; const sourceValue = source[key]; if (Array.isArray(sourceValue)) { diff --git a/src/utilities/common/filterInPlace.ts b/src/utilities/common/filterInPlace.ts deleted file mode 100644 index cafeed316f2..00000000000 --- a/src/utilities/common/filterInPlace.ts +++ /dev/null @@ -1,14 +0,0 @@ -export function filterInPlace( - array: T[], - test: (elem: T) => boolean, - context?: any -): T[] { - let target = 0; - array.forEach(function (elem, i) { - if (test.call(this, elem, i, array)) { - array[target++] = elem; - } - }, context); - array.length = target; - return array; -} diff --git a/src/utilities/common/mergeDeep.ts b/src/utilities/common/mergeDeep.ts index a2171f9f023..451a7a56a20 100644 --- a/src/utilities/common/mergeDeep.ts +++ b/src/utilities/common/mergeDeep.ts @@ -72,7 +72,7 @@ const defaultReconciler: ReconcilerFunction = function ( export class DeepMerger { constructor( - private reconciler: ReconcilerFunction = defaultReconciler + private reconciler: ReconcilerFunction = defaultReconciler as any as ReconcilerFunction ) {} public merge(target: any, source: any, ...context: TContextArgs): any { diff --git a/src/utilities/common/mergeOptions.ts b/src/utilities/common/mergeOptions.ts index 9c945f904e4..fe4eb954bbf 100644 --- a/src/utilities/common/mergeOptions.ts +++ b/src/utilities/common/mergeOptions.ts @@ -10,7 +10,7 @@ import { compact } from "./compact.js"; type OptionsUnion = | WatchQueryOptions | QueryOptions - | MutationOptions; + | MutationOptions; export function mergeOptions< TDefaultOptions extends Partial>, diff --git a/src/utilities/graphql/transform.ts b/src/utilities/graphql/transform.ts index 7ff844ad150..1693ee73fee 100644 --- a/src/utilities/graphql/transform.ts +++ b/src/utilities/graphql/transform.ts @@ -12,7 +12,7 @@ import type { FragmentSpreadNode, VariableDefinitionNode, ASTNode, - ASTVisitor, + ASTVisitFn, InlineFragmentNode, } from "graphql"; import { visit, Kind } from "graphql"; @@ -29,6 +29,12 @@ import type { FragmentMap } from "./fragments.js"; import { createFragmentMap } from "./fragments.js"; import { isArray, isNonEmptyArray } from "../common/arrays.js"; +// https://github.com/graphql/graphql-js/blob/8d7c8fccf5a9846a50785de04abda58a7eb13fc0/src/language/visitor.ts#L20-L23 +interface EnterLeaveVisitor { + readonly enter?: ASTVisitFn; + readonly leave?: ASTVisitFn; +} + export type RemoveNodeConfig = { name?: string; test?: (node: N) => boolean; @@ -208,8 +214,10 @@ export function removeDirectivesFromDocument( // original doc immediately without any modifications. let firstVisitMadeChanges = false; - const fieldOrInlineFragmentVisitor: ASTVisitor = { - enter(node: FieldNode | InlineFragmentNode) { + const fieldOrInlineFragmentVisitor: EnterLeaveVisitor< + FieldNode | InlineFragmentNode + > = { + enter(node) { if (shouldRemoveField(node.directives)) { firstVisitMadeChanges = true; return null; @@ -385,8 +393,10 @@ export function removeDirectivesFromDocument( ) ); - const enterVisitor: ASTVisitor = { - enter(node: FragmentSpreadNode | FragmentDefinitionNode) { + const enterVisitor: EnterLeaveVisitor< + FragmentSpreadNode | FragmentDefinitionNode + > = { + enter(node) { if (fragmentWillBeRemoved(node.name.value)) { return null; } diff --git a/src/utilities/observables/Concast.ts b/src/utilities/observables/Concast.ts index e6df7e19882..c2fbb6fb180 100644 --- a/src/utilities/observables/Concast.ts +++ b/src/utilities/observables/Concast.ts @@ -147,9 +147,9 @@ export class Concast extends Observable { // Any Concast object can be trivially converted to a Promise, without // having to create a new wrapper Observable. This promise provides an // easy way to observe the final state of the Concast. - private resolve: (result?: T | PromiseLike) => void; - private reject: (reason: any) => void; - public readonly promise = new Promise((resolve, reject) => { + private resolve!: (result?: T | PromiseLike) => void; + private reject!: (reason: any) => void; + public readonly promise = new Promise((resolve, reject) => { this.resolve = resolve; this.reject = reject; }); diff --git a/src/utilities/observables/Observable.ts b/src/utilities/observables/Observable.ts index 04fd25cac30..5ee33965f30 100644 --- a/src/utilities/observables/Observable.ts +++ b/src/utilities/observables/Observable.ts @@ -17,6 +17,7 @@ export type { Observer, ObservableSubscription, Subscriber }; const { prototype } = Observable; const fakeObsSymbol = "@@observable" as keyof typeof prototype; if (!prototype[fakeObsSymbol]) { + // @ts-expect-error prototype[fakeObsSymbol] = function () { return this; }; diff --git a/src/utilities/observables/__tests__/Observable.ts b/src/utilities/observables/__tests__/Observable.ts index 47223bc0643..1729e0ae1f3 100644 --- a/src/utilities/observables/__tests__/Observable.ts +++ b/src/utilities/observables/__tests__/Observable.ts @@ -39,8 +39,13 @@ describe("Observable", () => { return constructor as any; } + type ObservableWithSub = Observable & { sub?: Subscriber }; + it("simulating super(sub) with Observable.call(this, sub)", () => { - function SubclassWithSuperCall(sub: Subscriber) { + function SubclassWithSuperCall( + this: ObservableWithSub, + sub: Subscriber + ) { const self = Observable.call(this, sub) || this; self.sub = sub; return self; @@ -49,7 +54,10 @@ describe("Observable", () => { }); it("simulating super(sub) with Observable.apply(this, arguments)", () => { - function SubclassWithSuperApplyArgs(_sub: Subscriber) { + function SubclassWithSuperApplyArgs( + this: ObservableWithSub, + _sub: Subscriber + ) { const self = Observable.apply(this, arguments) || this; self.sub = _sub; return self; @@ -58,7 +66,10 @@ describe("Observable", () => { }); it("simulating super(sub) with Observable.apply(this, [sub])", () => { - function SubclassWithSuperApplyArray(...args: [Subscriber]) { + function SubclassWithSuperApplyArray( + this: ObservableWithSub, + ...args: [Subscriber] + ) { const self = Observable.apply(this, args) || this; self.sub = args[0]; return self; diff --git a/src/utilities/observables/__tests__/asyncMap.ts b/src/utilities/observables/__tests__/asyncMap.ts index e54b2140e66..491686d4f2c 100644 --- a/src/utilities/observables/__tests__/asyncMap.ts +++ b/src/utilities/observables/__tests__/asyncMap.ts @@ -25,6 +25,7 @@ function rejectExceptions( ) { return function () { try { + // @ts-expect-error return fn.apply(this, arguments); } catch (error) { reject(error); diff --git a/src/utilities/policies/pagination.ts b/src/utilities/policies/pagination.ts index 4dd000e32da..acb4c5af6f2 100644 --- a/src/utilities/policies/pagination.ts +++ b/src/utilities/policies/pagination.ts @@ -42,7 +42,7 @@ export function offsetLimitPagination( // to receive any arguments, so you might prefer to throw an // exception here, instead of recovering by appending incoming // onto the existing array. - merged.push.apply(merged, incoming); + merged.push(...incoming); } } diff --git a/src/utilities/types/TODO.ts b/src/utilities/types/TODO.ts new file mode 100644 index 00000000000..a5d637cc22c --- /dev/null +++ b/src/utilities/types/TODO.ts @@ -0,0 +1,2 @@ +/** @internal */ +export type TODO = any; diff --git a/tsconfig.json b/tsconfig.json index b03c9fb7fcb..a872c60ff05 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,7 +17,8 @@ "experimentalDecorators": true, "outDir": "./dist", "lib": ["es2015", "esnext.asynciterable", "dom"], - "jsx": "react" + "jsx": "react", + "strict": true }, "include": ["src/**/*.ts", "src/**/*.tsx"], "exclude": ["src/**/__tests__/**/*"] diff --git a/tsconfig.tests.json b/tsconfig.tests.json index d6bb25bd3fd..0908742da0d 100644 --- a/tsconfig.tests.json +++ b/tsconfig.tests.json @@ -1,5 +1,3 @@ { - "extends": "./tsconfig.json", - "include": ["src/**/__tests__/**/*.ts", "src/**/__tests__/**/*.tsx"], - "exclude": [] + "extends": "./src/tsconfig.json" }