joken-前端工程师

  :: 首页 :: 博问 :: 闪存 :: 新随笔 :: :: :: 管理 ::

代码

  • 联合类型、交叉类型
//联合类型

type abcNewType = string | number;

type abcNewType2 = "a" | "b" | "c";


interface a1 {
  a: string
}
interface a2 {
  b: string
}

//交叉类型
type ab = a1 & a2;

let ab1: ab = {
  a: "a",
  b: "b"
}

console.log(ab1, "ab1")
  • type interface 互相继承方式

interface 继承其他基本都是extends 类型

type继承其他基本都是直接等于放入类型即可

// type继承 type方式
type ab3 = a2 & { c: string }


//interface 继承interface 方式,使用extends
interface a3 extends a1, a2 {
  c: string
}
//interface继承type方式,使用extends
interface a4 extends ab3 { }

//type继承interface方式,直接放入即可
type t6 = a4 & { d: string }

//Partial代表属性可选
type t7 = Partial<t6>
posted on 2024-06-24 22:12  joken1310  阅读(3)  评论(0编辑  收藏  举报