typescriptクラスは型定義として拡張できます

// 定义一个class类
class Poin2 {
    
    
  x: number;
  y: number;
  constructor(x: number, y: number) {
    
    
    this.x = x;
    this.y = y;
  }
}

// 作为类型使用
const test1:Poin2 = {
    
    
  x: 1,
  y: 2
}

// 被接口扩展
interface Point3d extends Poin2 {
    
    
  z: number;
}

const btn: Point3d = {
    
    
  x: 1,
  y: 2,
  z: 3,
};

// 被类型别名扩展
type fhsadjk = {
    
    
  z: string;
} & Poin2;

const btn1: fhsadjk = {
    
    
  z: '123',
  x:1,
  y: 2
}

おすすめ

転載: blog.csdn.net/glorydx/article/details/112625642