Skip to content

Commit 84a63d8

Browse files
committed
docs(solid-query): recommend defaultError = unknown instead of AxiosError
Signed-off-by: leesb971204 <[email protected]>
1 parent ba4a117 commit 84a63d8

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎docs/framework/solid/typescript.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,15 @@ if (axios.isAxiosError(query.error)) {
129129

130130
[typescript playground](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYygUwIYzQRQK5pQCecAvnAGZQQhwDkAAjBgHYDOzyA1gPRsQAbYABMAtAEcCxOgFgAUKEiw4GAB7AIbStVp01GtrLnyYRMGjgBxanjBwAvIjgiAXHBZ4QAI0Jl585Ah2eAo0GGQAC2sIWy1HAAoASjcABR1gNjQAHmjbAG0AXQA+BxL9TQA6AHMw+LoeKpswQ0SKmAi0Fnj0Nkh2C3sSnr7MiuEsDET-OUDguElCEkdUTGx8Rfik0rh4hHk4A-mpIgBpNCI3PLpGmOa6AoAaOH3DheIAMRY3UPCoprYHvJSIkpsY5G8iBVCNQoPIeDxDnAAHoAfmmwAoO3KbAqGQAgupNABRKAw+IQqGk6AgxAvA4U6HQOlweGI1FA+RAA)
131131

132-
## Registering a global `Error`
133-
134-
TanStack Query v5 allows for a way to set a global Error type for everything, without having to specify generics on call-sides, by amending the `Register` interface. This will make sure inference still works, but the error field will be of the specified type:
132+
[//]: # 'RegisterErrorType'
135133

136134
```tsx
137135
import '@tanstack/solid-query'
138136

139137
declare module '@tanstack/solid-query' {
140138
interface Register {
141-
defaultError: AxiosError
139+
// Use unknown so call sites must narrow explicitly.
140+
defaultError: unknown
142141
}
143142
}
144143

@@ -148,9 +147,11 @@ const query = useQuery(() => ({
148147
}))
149148

150149
query.error
151-
// ^? (property) error: AxiosError | null
150+
// ^? (property) error: unknown | null
152151
```
153152

153+
[//]: # 'RegisterErrorType'
154+
154155
## Registering global `Meta`
155156

156157
Similarly to registering a [global error type](#registering-a-global-error) you can also register a global `Meta` type. This ensures the optional `meta` field on [queries](../reference/useQuery.md) and [mutations](../reference/useMutation.md) stays consistent and is type-safe. Note that the registered type must extend `Record<string, unknown>` so that `meta` remains an object.

0 commit comments

Comments
 (0)