开发人员在一个对象中定义了这样的代码常量:
medium: {
fontFamily: 'Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif',
fontWeight: '500' as '500',
},
as关键字在做什么?
指此问题的答案What does the "as" keyword do?
as
关键字是TypeScript中的类型断言,它告诉编译器将对象视为不同于编译器推断为对象的类型的另一种类型。
var a = 'TEST STRING'
var b = a as string; //Means the compiler will assume it's a string