3

I have an interface like this:

export interface IDefaultAction extends Object {
  type: string
  (dispatch: Dispatch<IStateObject>, getState: () => IStateObject, extraArgument: any): any;
}

is there any way I can make the second line in the interface optional? (dispatch: Dispatch<IStateObject>, getState: () => IStateObject, extraArgument: any): any;

and if so, how?

and also if possible please explain or point me to the right documentation which explains what does this interface mean:

interface IA {
  ():any;
}

I just can't figure out this syntax

():something;

Thanks!

edit:

I am trying to extend this:

export type ThunkAction<R, S, E> = (dispatch: Dispatch<S>, getState: () => S,
                                    extraArgument: E) => R;

in my own interface:

export interface IDefaultAction {
  type: string;
}

but optionally, so the only thing I could think of, is to modify the original(ThunkAction) and make all inside it optional, but I don't see how.

1 Answer 1

5

please explain or point me to the right documentation which explains what does this interface mean:

The IA interface is a function interface. It defines a "function type".

interface IA {
    (): any;
}

const exampleImplementation: IA = () => "";

The (): any defines the function type's signature, which includes the function's parameter list and return type. The function type IA takes no parameters and returns an any.

is there any way I can make the second line in the interface optional?

The second line is a function signature, which means that the interface defines a function type. Its function signature takes two parameters and returns an any.

export interface IDefaultAction extends Object {
  type: string;
  (
    dispatch: Dispatch<IStateObject>,                  // paramater 1
    getState: () => IStateObject, extraArgument: any   // parameter 2
  ) : any;                                             // return type
}

While interfaces support optional properties, interfaces do not support optional function signatures.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.