as
是 TypeScript 中类型断言的附加语法。引入 as-syntax
的原因是原始语法 (<type>
) 与 JSX 冲突。
例子
let empCode: any = 111;
let employeeCode = code as number;
将 TypeScript 与 JSX 一起使用时,只允许使用 as 样式的断言。
42、TypeScript 中的“as”语法是什么?
as
是 TypeScript 中类型断言的附加语法。引入 as-syntax
的原因是原始语法 (<type>
) 与 JSX 冲突。
例子
let empCode: any = 111;
let employeeCode = code as number;
将 TypeScript 与 JSX 一起使用时,只允许使用 as 样式的断言。