UNPKG

@apollo/client

Version:

A fully-featured caching GraphQL client.

35 lines 1.29 kB
/** * Helper type that allows using a type in a way that cannot be "widened" by inference on the value it is used on. * * This type was first suggested [in this Github discussion](https://github.com/microsoft/TypeScript/issues/14829#issuecomment-504042546). * * Example usage: * * ```ts * export function useQuery< * TData = unknown, * TVariables extends OperationVariables = OperationVariables, * >( * query: DocumentNode | TypedDocumentNode<TData, TVariables>, * options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>> = {} * ); * ``` * * In this case, `TData` and `TVariables` should be inferred from `query`, but never widened from something in `options`. * * So, in this code example: * * ```ts * declare const typedNode: TypedDocumentNode<{ foo: string }, { bar: number }>; * const { variables } = useQuery(typedNode, { * variables: { bar: 4, nonExistingVariable: "string" }, * }); * ``` * * Without the use of `NoInfer`, `variables` would now be of the type `{ bar: number, nonExistingVariable: "string" }`. * With `NoInfer`, it will instead give an error on `nonExistingVariable`. * * @deprecated use the official `NoInfer` type instead. */ export type NoInfer<T> = [T][T extends any ? 0 : never]; //# sourceMappingURL=NoInfer.d.ts.map