打字稿界面使可选
Typescript Interface make optional
我有这样的界面:
export interface IDefaultAction extends Object {
type: string
(dispatch: Dispatch<IStateObject>, getState: () => IStateObject, extraArgument: any): any;
}
有什么方法可以让界面中的第二行成为可选的吗?
(dispatch: Dispatch<IStateObject>, getState: () => IStateObject, extraArgument: any): any;
如果是,怎么做?
如果可能的话,请解释或指出正确的文档来解释这个界面的含义:
interface IA {
():any;
}
我就是搞不懂这个语法
():something;
谢谢!
编辑:
我正在尝试扩展它:
export type ThunkAction<R, S, E> = (dispatch: Dispatch<S>, getState: () => S,
extraArgument: E) => R;
在我自己的界面中:
export interface IDefaultAction {
type: string;
}
但可选地,
所以我唯一能想到的就是修改原来的(ThunkAction)并使它里面的所有内容都是可选的,但我不知道怎么做。
please explain or point me to the right documentation which explains what does this interface mean:
IA
接口是函数接口。它定义了 a "function type"。
interface IA {
(): any;
}
const exampleImplementation: IA = () => "";
(): any
定义函数类型的签名,包括函数的参数列表和return类型。函数类型 IA
没有参数并且 return 是一个 any
.
is there any way I can make the second line in the interface optional?
第二行是函数签名,表示接口定义了一个函数类型。它的函数签名有两个参数和 returns 一个 any
.
export interface IDefaultAction extends Object {
type: string;
(
dispatch: Dispatch<IStateObject>, // paramater 1
getState: () => IStateObject, extraArgument: any // parameter 2
) : any; // return type
}
虽然接口支持 optional properties,但接口不支持可选函数签名。
我有这样的界面:
export interface IDefaultAction extends Object {
type: string
(dispatch: Dispatch<IStateObject>, getState: () => IStateObject, extraArgument: any): any;
}
有什么方法可以让界面中的第二行成为可选的吗?
(dispatch: Dispatch<IStateObject>, getState: () => IStateObject, extraArgument: any): any;
如果是,怎么做?
如果可能的话,请解释或指出正确的文档来解释这个界面的含义:
interface IA {
():any;
}
我就是搞不懂这个语法
():something;
谢谢!
编辑:
我正在尝试扩展它:
export type ThunkAction<R, S, E> = (dispatch: Dispatch<S>, getState: () => S,
extraArgument: E) => R;
在我自己的界面中:
export interface IDefaultAction {
type: string;
}
但可选地, 所以我唯一能想到的就是修改原来的(ThunkAction)并使它里面的所有内容都是可选的,但我不知道怎么做。
please explain or point me to the right documentation which explains what does this interface mean:
IA
接口是函数接口。它定义了 a "function type"。
interface IA {
(): any;
}
const exampleImplementation: IA = () => "";
(): any
定义函数类型的签名,包括函数的参数列表和return类型。函数类型 IA
没有参数并且 return 是一个 any
.
is there any way I can make the second line in the interface optional?
第二行是函数签名,表示接口定义了一个函数类型。它的函数签名有两个参数和 returns 一个 any
.
export interface IDefaultAction extends Object {
type: string;
(
dispatch: Dispatch<IStateObject>, // paramater 1
getState: () => IStateObject, extraArgument: any // parameter 2
) : any; // return type
}
虽然接口支持 optional properties,但接口不支持可选函数签名。