vas*_*ich 3 typescript typescript-typings typescript2.0
我有这样的界面:
export interface IDefaultAction extends Object {
type: string
(dispatch: Dispatch<IStateObject>, getState: () => IStateObject, extraArgument: any): any;
}
Run Code Online (Sandbox Code Playgroud)
有什么办法可以让界面中的第二行可选吗?
(dispatch: Dispatch<IStateObject>, getState: () => IStateObject, extraArgument: any): any;
如果是的话,怎么样?
如果可能的话,请向我解释或指出正确的文档,该文档解释了此接口的含义:
interface IA {
():any;
}
Run Code Online (Sandbox Code Playgroud)
我只是无法弄清楚这种语法
():something;
Run Code Online (Sandbox Code Playgroud)
谢谢!
编辑:
我想扩展这个:
export type ThunkAction<R, S, E> = (dispatch: Dispatch<S>, getState: () => S,
extraArgument: E) => R;
Run Code Online (Sandbox Code Playgroud)
在我自己的界面:
export interface IDefaultAction {
type: string;
}
Run Code Online (Sandbox Code Playgroud)
但是可选地,所以我唯一能想到的就是修改原始(ThunkAction)并使其中的所有内部都是可选的,但我不知道如何.
请解释或指向正确的文档,该文档解释了此接口的含义:
该IA接口是一个功能界面.它定义了"函数类型".
interface IA {
(): any;
}
const exampleImplementation: IA = () => "";
Run Code Online (Sandbox Code Playgroud)
该(): any定义函数类型的签名,其中包括函数的参数列表和返回类型.函数类型IA不带参数并返回any.
有什么办法可以让界面中的第二行可选吗?
第二行是函数签名,这意味着接口定义了函数类型.它的函数签名有两个参数并返回一个any.
export interface IDefaultAction extends Object {
type: string;
(
dispatch: Dispatch<IStateObject>, // paramater 1
getState: () => IStateObject, extraArgument: any // parameter 2
) : any; // return type
}
Run Code Online (Sandbox Code Playgroud)
虽然接口支持可选属性,但接口不支持可选功能签名.
| 归档时间: |
|
| 查看次数: |
523 次 |
| 最近记录: |