Skip to content
Myr

fix(devtools): improve type inference for Devtools initializer (#3511)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix(devtools): improve type inference for Devtools initializer * fix(devtools): enhance type inference for Devtools initializer * test(types): add devtools inference regression for #3510 * Rename options parameter to devtoolsOptions * test(types): fix lint in devtools #3510 regression case * test(types): simplify lint-safe ts-expect-error expression ---------

authored by Danilo Britto · committed by GitHub · parent 8476d2c · Browse files · 2 files+23 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
  • Co-authored-by: Daishi Kato <dai-shi@users.noreply.github.com>

Diff stats

2 files+23 added−1 removed

  • tests:+22 added−0 removed
  • other:+1 added−1 removed

2 files+23 added−1 removed

modified:src/middleware/devtools.ts+1 added-1 removed
94 unmodified lines
95 U = T,96>(97 initializer: StateCreator<T, [...Mps, ['zustand/devtools', never]], Mcs, U>,98 devtoolsOptions?: DevtoolsOptions,99) => StateCreator<T, Mps, [['zustand/devtools', never], ...Mcs]>99) => StateCreator<T, Mps, [['zustand/devtools', never], ...Mcs], U>100101type DevtoolsImpl = <T>(102 storeInitializer: StateCreator<T, [], []>,103 devtoolsOptions?: DevtoolsOptions,
335 unmodified lines
modified:tests/middlewareTypes.test.tsx+22 added
196 unmodified lines
197 const useStoreD = create<TableStore | null>()(() => null)198 expect(useStoreD).toBeDefined()199 })200201 it('devtools #3510', () => {202 type MyState = {203 count: number204 inc: () => void205 }206207 const useBoundStore = create<MyState>()(208 devtools((set, get) => ({209 count: 0,210 inc: () => {211 set({ count: get().count + 1 }, false, 'inc')212 // @ts-expect-error `get` should be inferred as `MyState`.213 void get().foo214 // @ts-expect-error `set` should enforce `count` as number.215 set({ count: '1' })216 },217 })),218 )219220 expect(useBoundStore).toBeDefined()221 })222223 it('subscribeWithSelector', () => {224 const useBoundStore = create<CounterState>()(225 subscribeWithSelector((set, get) => ({226 count: 1,
633 unmodified lines