JavaScript/typescript/typeof:修订间差异
来自康健生活
< JavaScript | typescript
创建页面,内容为“== 引言 == == const == typeof 操作符配合 const 断言获取元组中元素值的联合类型。 <syntaxhighlight lang="javascript"> /** * 设置 button 原…” |
|||
| 第1行: | 第1行: | ||
== 引言 == | == 引言 == | ||
== const == | == const == | ||
=== readonly === | |||
=== 联合类型 === | |||
typeof 操作符配合 const 断言获取元组中元素值的联合类型。 | typeof 操作符配合 const 断言获取元组中元素值的联合类型。 | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
2021年3月7日 (日) 10:21的最新版本
引言
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";
}
No categories