-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Are there type definitions for TypeScript for *.funcs.ts files #23
Comments
@SoftHai, thank you for the detailed explanation. I'll add some TS typings into the As a workaround, I'd like to suggest using the following example:
import { History } from 'history';
import { PrimaryButtonProps } from './PrimaryButton.comp';
type SetTextStateOptions = {
stateByDispatch: PrimaryButtonProps;
history: History;
};
// Specify this in the global index.d.ts
type DispatchFunction = (arg0: any) => void;
export const setText = (text: string, stateOptions: SetTextStateOptions) => (dispatch: DispatchFunction) => {
const { stateByDispatch, history } = stateOptions;
// ...
// OR
// const hist: History = stateOptions.history;
// const stateByDispatch: PrimaryButtonProps = stateOptions.stateByDispatch;
//...
}; |
Yes, that's correct. |
Hi, cool. |
@SoftHai, thank you. I'll keep this issue until I add this as an example to the User Guide. |
It seems that my example is not correct. Please consider my following example for TS types in function. global.d.ts import { History } from 'history';
export type DispatchFunction<T> = (arg0: T) => void;
export interface StateOptions<T> {
stateByDispatch: T;
history: History;
} functionExamples.funcs.ts import { StateOptions, DispatchFunction } from "typings/global";
import { PrimaryButtonProps } from './PrimaryButton.comp';
interface StateByDispatch {
props?: PrimaryButtonProps;
}
interface DispatchOptions extends StateByDispatch {
// here we already have output fields from StateByDispatch
// add additional fields for the dispatch output
}
export const setText = (textValue: string, stateOptions: StateOptions<StateByDispatch>) => (dispatch: DispatchFunction<DispatchOptions>) => {
const { stateByDispatch, history } = stateOptions;
if (stateByDispatch) {
const {props} = stateByDispatch;
dispatch({props: {...props, text: textValue}});
}
}; How it is used on the flow: |
Hi,
creating a function with TypeScript will end in some type check "errors" for the parameters:

Are there TS type definitions for at least a few of the parameters (like dispatch, history, ...). Option and StateOfDispatch are types which has to be defined in the specific application, isn't it?
Actual you have to define the type definition by your own:

Or use a
// @ts-ignore
to ignore the errors.The text was updated successfully, but these errors were encountered: