diff --git a/types/use-global-hook/index.d.ts b/types/use-global-hook/index.d.ts index 266a426a15..19ad7e56a8 100644 --- a/types/use-global-hook/index.d.ts +++ b/types/use-global-hook/index.d.ts @@ -23,4 +23,4 @@ export default function useStore( inititalState: S, actions: object, initializers?: InitializerFunction, -): () => [S, A]; +): (stateFunc?: (state: S) => NS, actionsFunc?: (state: A) => NA) => [NS, NA]; diff --git a/types/use-global-hook/use-global-hook-tests.ts b/types/use-global-hook/use-global-hook-tests.ts index e13973e83e..c2ceaaa05e 100644 --- a/types/use-global-hook/use-global-hook-tests.ts +++ b/types/use-global-hook/use-global-hook-tests.ts @@ -1,13 +1,28 @@ import useStore, { Store, InitializerFunction } from 'use-global-hook'; import React = require('react'); -interface state { value: string; } -interface associatedActions { setValue(value: string): void; } -const initializer: InitializerFunction = (store: Store) => { - store.actions.setValue(""); +interface stateType { + value: string; +} + +type setFunc = (value: string) => void; + +interface associatedActionsType { + setValue: setFunc; +} + +const initializer: InitializerFunction = (store: Store) => { + store.actions.setValue(''); store.state.value; - store.setState({ value: "string" }); + store.setState({ value: 'string' }); }; -useStore(React, { value: "" }, {}, initializer); // $ExpectType () => [state, associatedActions] -useStore(React, { value: "" }, {}); // $ExpectType () => [state, associatedActions] +const store = useStore(React, { value: '' }, {}, initializer); + +store(); // $ExpectType [unknown, unknown] +store(); // $ExpectType [stateType, associatedActionsType] +store((state: stateType) => state.value); // $ExpectType [string, associatedActionsType] +store(undefined, (action: associatedActionsType) => action.setValue); // $ExpectType [stateType, setFunc] +store((state: stateType) => state.value, (actions: associatedActionsType) => actions.setValue); // $ExpectType [string, setFunc] + +useStore(React, { value: '' }, {});