JavaScript/typescript/typeof

来自康健生活

引言

const

readonly

联合类型

typeof 操作符配合 const 断言获取元组中元素值的联合类型。

/**
 * 设置 button 原生的 type 值。htmlType
 */
 export const ButtonProtoTypes = [
    "button",
    "reset",
    "submit"
  ] as const;

/**
 * 设置 button 的基础各种 type
 * typeof 操作符配合 const 断言获取元组中元素值的联合类型
 */
 export interface ButtonBaseTypes {
    htmlType?: typeof ButtonProtoTypes[number];
    // 等于于
    // htmlType?: "button" | "reset" | "submit";
  }