【发布时间】:2022-01-12 05:24:31
【问题描述】:
function identity<String>(arg: String): String {
return arg;
}
let myIdentity = identity([2]);
console.log()
嗨,有人能帮我理解为什么即使我传递一个数字数组也不会引发任何类型错误吗?
- 是不是因为类型是 "String" 而不是 "string" ,它查找对象而不是原始对象?
- 如果答案是“是”,如果我将所有内容都更改为字符串,我会收到错误消息说从未使用过字符串
function identity<string>(arg: string): string {
return arg;
}
let myIdentity = identity([2]);
console.log(myIdentity )
'string' is declared but its value is never read.
【问题讨论】:
标签: javascript typescript typescript-typings