UNPKG

@apollo/client

Version:

A fully-featured caching GraphQL client.

27 lines (24 loc) 1.16 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 = any, TVariables extends OperationVariables = OperationVariables, >( query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>> = Object.create(null), ) ``` 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`. */ export type NoInfer<T> = [T][T extends any ? 0 : never]; //# sourceMappingURL=NoInfer.d.ts.map