[英]How to understand this generic interface definition in TypeScript?
Does the definition of this Cache
type, Cache<V = any>
, define an object or a function?此
Cache
类型的定义Cache<V = any>
是否定义了对象或函数?
Here the generic V
, why specify an any
?这里是通用的
V
,为什么要指定any
? What does the equals sign mean?等号是什么意思?
export interface Cache<V = any> {
value?: V;
timeoutId?: ReturnType<typeof setTimeout>;
time?: number;
alive?: number;
}
Cache
defines an object here. Cache
在这里定义了一个对象。 V = any
means that V
is of type any
if no generic value
is provided, and the value in this object is also of type any
. V = any
表示如果没有提供泛型value
,则V
的类型为any
,并且此对象中的值也是any
类型。 The equal sign here means the default value.这里的等号表示默认值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.