typescript 使用传递Type的Typescript继承

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了typescript 使用传递Type的Typescript继承相关的知识,希望对你有一定的参考价值。

interface Item<T> { 
   id: T
   name: string
   price: number
} 

interface Product extends Item<number> {
   stock: number
}

interface Service extends Item<string> {}


const item1 = <Product> {}

item1.id = 1;
item1.name = "Juice";
item1.price = 5.00;

const item2 = <Service> {}

item2.id = 'ServiceABC';
item2.name = "Juice";
item2.price = 5.00;

以上是关于typescript 使用传递Type的Typescript继承的主要内容,如果未能解决你的问题,请参考以下文章

在 Typescript 2.0 中使用 @types 类型定义

TypeScript中的实用工具类型(Utility Types)

[Typescript] Installing Promise Type Definitions Using the lib Built-In Types

typescript 使用传递Type的Typescript继承

[TypeScript] Distinguishing between types of Strings in TypeScript

[TypeScript] Typescript Interfaces vs Aliases Union & Intersection Types