File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,9 +8,11 @@ import {
88import { getIdFromAction } from "./action.js" ;
99import type { ThunkAction } from "./query/index.js" ;
1010import {
11+ type DefaultSchemaKey ,
1112 type FxSchema ,
1213 type FxStore ,
1314 PERSIST_LOADER_ID ,
15+ type StoreSchemaRegistry ,
1416} from "./store/index.js" ;
1517import type { LoaderOutput } from "./store/slice/loaders.js" ;
1618import type { TableOutput } from "./store/slice/table.js" ;
@@ -180,9 +182,12 @@ export function createTypedHooks<O extends FxMap>(
180182 * }
181183 * ```
182184 */
183- export function Provider < O extends FxMap > ( props : {
184- store : FxStore < O > ;
185- schema ?: FxSchema < O > ;
185+ export function Provider <
186+ O extends FxMap ,
187+ TSchemas extends StoreSchemaRegistry = StoreSchemaRegistry < FxSchema < O > > ,
188+ > ( props : {
189+ store : FxStore < O , TSchemas > ;
190+ schema ?: TSchemas [ DefaultSchemaKey ] ;
186191 children ?: React . ReactNode ;
187192} ) : React . ReactElement ;
188193
Original file line number Diff line number Diff line change 11import { describe , expectTypeOf , test } from "vitest" ;
2+ import type { ReactElement } from "react" ;
23import type { ThunkAction } from "../query/index.js" ;
34import {
5+ Provider ,
46 type UseApiAction ,
57 type UseApiProps ,
68 type UseApiSimpleProps ,
@@ -139,6 +141,22 @@ describe("react hook types", () => {
139141 expectTypeOf ( useSchemaState ) . returns . toEqualTypeOf < typeof schema > ( ) ;
140142 expectTypeOf ( useTypedLoader ) . returns . toEqualTypeOf < LoaderState > ( ) ;
141143 } ) ;
144+
145+ test ( "Provider accepts stores with merged root state and narrower default schema" , ( ) => {
146+ const baseSchema = createSchema ( {
147+ users : slice . table < User > ( ) ,
148+ } ) ;
149+ const metadataSchema = createSchema ( {
150+ metadata : slice . obj < Metadata > ( { } ) ,
151+ } ) ;
152+ const store = createStore ( {
153+ schema : { default : baseSchema , metadata : metadataSchema } ,
154+ } ) ;
155+
156+ const renderProvider = ( ) => Provider ( { store, children : null } ) ;
157+
158+ expectTypeOf ( renderProvider ) . returns . toEqualTypeOf < ReactElement > ( ) ;
159+ } ) ;
142160 } ) ;
143161
144162 describe ( "direct hooks with explicit schema generics" , ( ) => {
You can’t perform that action at this time.
0 commit comments