我正在学习type typescript泛型,并遇到下面的泛型类型,并使用相等的操作符表示扩展类型。
export interface DataType {
[key: string]: FieldValue;
}
export interface FormProps<Data extends DataType = DataType> { }DataType = DataType在这里是什么意思?
发布于 2019-07-02 00:06:33
如果不提供类型Data (必须扩展DataType),它将默认为DataType。
从以前的发行说明
假设一个函数创建了一个新的HTMLElement,调用它时没有参数,就会生成一个Div;您也可以选择传递一个子元素列表。以前,您必须将其定义为: 声明函数创建():Container;声明函数创建(元素: T):Container; 对于泛型参数默认值,我们可以将其简化为: 声明函数创建(元素: T,子元素?:U):Container; 泛型参数默认值遵循以下规则:
https://stackoverflow.com/questions/56843790
复制相似问题