Skip to content

Commit e9946eb

Browse files
authored
Update README.md
1 parent eb0252a commit e9946eb

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

README.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,19 +224,35 @@ const pokemonLoader = baseLoader.extend({
224224

225225
New properties will overwrite existing.
226226

227-
> If the loader you extend has a `transform` function, and you are changing the `queries` function, you might need to do this to resolve the types properly:
227+
**NOTE**:
228+
229+
> If the loader that you _extend from_ has a `transform` function, and you are change the `queries` function in the _extended_ loader, you might need to do the following fix to resolve the types correctly:
228230
229231
```typescript
230232
const baseLoader = createLoader({
231233
queries: () => [...],
232234
transform: () => {i_want: "this-format"},
233235
})
234236

235-
const pokemonLoader = baseLoader.extend({
237+
// This first example is extending a loader that has a transform.
238+
// It does not supply a new transform function
239+
const extendedOne = baseLoader.extend(({
240+
queries: () => [...],
241+
}))
242+
243+
type TestOne = InferLoaderData<typeof extendedOne>;
244+
// Resolves to: { i_want: string; }
245+
// which is incorrect. In reality it defaults to your list of queries.
246+
247+
// In this example, we supply a transform function as well:
248+
const extendedTwo = baseLoader.extend({
236249
queries: () => [...],
237-
transform: (q) => q, // Reapply default transform for query
250+
transform: (q) => q, // This is essentially the default value
238251
});
239252

240-
type Test = ReturnType<typeof pokemonLoader>;
241-
// { i_want: string; }
253+
type TestTwo = InferLoaderData<typeof extendedTwo>;
254+
// Resolves to: readonly [UseQueryResult<...>]
255+
// which is correct.
242256
```
257+
258+
> This is just a type mistake that will hopefully be fixed in the future. Both `extendedOne` and `extendedTwo` return the same format, but `extendedTwo` has the correct types.

0 commit comments

Comments
 (0)