mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-01 15:50:13 +00:00
Adds type support for subset declaration (#38617)
This commit is contained in:
2
types/use-global-hook/index.d.ts
vendored
2
types/use-global-hook/index.d.ts
vendored
@@ -23,4 +23,4 @@ export default function useStore<S, A>(
|
||||
inititalState: S,
|
||||
actions: object,
|
||||
initializers?: InitializerFunction<S, A>,
|
||||
): () => [S, A];
|
||||
): <NS, NA>(stateFunc?: (state: S) => NS, actionsFunc?: (state: A) => NA) => [NS, NA];
|
||||
|
||||
@@ -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<state, associatedActions> = (store: Store<state, associatedActions>) => {
|
||||
store.actions.setValue("");
|
||||
interface stateType {
|
||||
value: string;
|
||||
}
|
||||
|
||||
type setFunc = (value: string) => void;
|
||||
|
||||
interface associatedActionsType {
|
||||
setValue: setFunc;
|
||||
}
|
||||
|
||||
const initializer: InitializerFunction<stateType, associatedActionsType> = (store: Store<stateType, associatedActionsType>) => {
|
||||
store.actions.setValue('');
|
||||
store.state.value;
|
||||
store.setState({ value: "string" });
|
||||
store.setState({ value: 'string' });
|
||||
};
|
||||
|
||||
useStore<state, associatedActions>(React, { value: "" }, {}, initializer); // $ExpectType () => [state, associatedActions]
|
||||
useStore<state, associatedActions>(React, { value: "" }, {}); // $ExpectType () => [state, associatedActions]
|
||||
const store = useStore<stateType, associatedActionsType>(React, { value: '' }, {}, initializer);
|
||||
|
||||
store(); // $ExpectType [unknown, unknown]
|
||||
store<stateType, associatedActionsType>(); // $ExpectType [stateType, associatedActionsType]
|
||||
store<string, associatedActionsType>((state: stateType) => state.value); // $ExpectType [string, associatedActionsType]
|
||||
store<stateType, setFunc>(undefined, (action: associatedActionsType) => action.setValue); // $ExpectType [stateType, setFunc]
|
||||
store<string, setFunc>((state: stateType) => state.value, (actions: associatedActionsType) => actions.setValue); // $ExpectType [string, setFunc]
|
||||
|
||||
useStore<stateType, associatedActionsType>(React, { value: '' }, {});
|
||||
|
||||
Reference in New Issue
Block a user