Skip to content

Commit

Permalink
fix(middleware): devtools type error #2700 (#2875)
Browse files Browse the repository at this point in the history
* fix: add an inferred generic U to CreateStoreImpl

* fix: add inferred generic U variables to both Devtools and DevtoolsImpl

* test: add tests for issue #2700

* revert impl types

* code styling

---------

Co-authored-by: daishi <daishi@axlight.com>
  • Loading branch information
AndyRightNow and dai-shi authored Dec 4, 2024
1 parent 5ed67ec commit af7ff21
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/middleware/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ type Devtools = <
T,
Mps extends [StoreMutatorIdentifier, unknown][] = [],
Mcs extends [StoreMutatorIdentifier, unknown][] = [],
U = T,
>(
initializer: StateCreator<T, [...Mps, ['zustand/devtools', never]], Mcs>,
initializer: StateCreator<T, [...Mps, ['zustand/devtools', never]], Mcs, U>,
devtoolsOptions?: DevtoolsOptions,
) => StateCreator<T, Mps, [['zustand/devtools', never], ...Mcs]>

Expand Down
18 changes: 18 additions & 0 deletions tests/middlewareTypes.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,24 @@ describe('counter state spec (single middleware)', () => {
expect(testSubtyping).toBeDefined()
})

it('devtools #2700', () => {
type TableStore = {
table: string
}
const useStoreA = create<TableStore | null>()(
devtools((_set) => null, { name: 'table-storage' }),
)
expect(useStoreA).toBeDefined()
const useStoreB = create<TableStore | null>()(
devtools(() => null, { name: 'table-storage' }),
)
expect(useStoreB).toBeDefined()
const useStoreC = create<TableStore | null>()((_set) => null)
expect(useStoreC).toBeDefined()
const useStoreD = create<TableStore | null>()(() => null)
expect(useStoreD).toBeDefined()
})

it('subscribeWithSelector', () => {
const useBoundStore = create<CounterState>()(
subscribeWithSelector((set, get) => ({
Expand Down

0 comments on commit af7ff21

Please sign in to comment.