简体   繁体   English

如何理解 TypeScript 中的这个通用接口定义?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM