string类型为什么是Object
来源:11-31 【元数据操作】 理解 reflect-metadata 元数据操作重载方法和其他方法 2

crazyones110
2021-10-07
class Test {
@Reflect.metadata("aa", "bb")
name = "xxx";
}
Reflect.getMetadataKeys(Test.prototype, "name").forEach(metadataKey => {
console.log(metadataKey, Reflect.getMetadata(metadataKey, Test.prototype, "name"));
})
// 打印出design:type [Function: Object]
class Test {
@Reflect.metadata("aa", "bb")
name: string = "xxx";
}
Reflect.getMetadataKeys(Test.prototype, "name").forEach(metadataKey => {
console.log(metadataKey, Reflect.getMetadata(metadataKey, Test.prototype, "name"));
})
// 打印出design:type [Function: String]
仅仅是显式指明类型是string, design:type的类型就正确了, 这是为什么
写回答
1回答
-
是的, 当你不加具体类型时,比如: name=["abc","cde"] design:type 输出的结果都是object , 元数据 design:type认为 name:string="abc" name="abc" 还是有区别的 , name="abc" 后面的"abc" 可以改成任何类型的值 ,所以可以被design:type输出为object ,但是name:string="abc" 后面只能是字符串
112021-10-07
相似问题