有两个报错 Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'. 因为foo作为object没有声明string类型可用,所以foo[key]将会是any类型。 No index signaturewitha parameteroftype'string'was found ontype'{}'. object没有找到string类型的 解决...
typescript常见问题集锦 1.在ts中,碰到Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Object'. No index signature with a parameter of type 'string' was found on type 'Object'. 这种问题测出现时说:元素隐式具有“any”类型,因为“string”...
Error: src/app/routes/first/testmvvmtable/testmvvmtable.component.html:13:15 - error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'ResourceVmRespData'. No index signature with a parameter of type 'string' was found on type...
type Value1 = { name: string; }; 因为type alias 不能像 interface 那样可以重复声明,所以 type alias 会被 infer an implicit index signature: //当我们这样: test = value_1; //Value1 其实被 infer 成这样了: type Value1 = { name: string; [key: string]: string; }; //所以 Test 和 ...
如上的代码在编译器当中是会报错的,报错的原因就是它不知道 obj[key] 返回的到底是不是 any 这个...
// No index signature with a parameter of type 'string' was found on type '{ name: string; age: number; }'. TypeScript返回一个字符串数组是有充分理由的。TypeScript 对象类型是开放的。 有许多情况下,TS 无法保证由 Object.keys 返回的键实际上存在于对象中 - 因此将它们扩大为字符串是唯一合理的...
我总是用标志--noImplicitAny编译 TypeScript。这是有道理的,因为我希望我的类型检查尽可能严格。 我的问题是使用以下代码出现错误: Indexsignatureofobjecttypeimplicitly has an'any'type interface ISomeObject { firstKey:string; secondKey:string; thirdKey:string; ...
string类型,是我们最常用的。以及一些特性,我们都比较熟悉,这一节一起回顾一下string的应用场景,以及...
TypeScript Version: 2.2.2 Code function getName(id: number) { return { 1: 'one', 2: 'two', }[id] || 'something else'; } Expected behavior: {1: 'one'}[id] type should be string | undefined So I would expect the return type to be inferred ...
TypeScript Version: 2.8.3-insiders.20180407 (Also in the Playground) Search Terms: index signature Code let x: string = "x"; x = 1; // As expected, this line doesn't compile interface Obj { [id: string]: boolean; } let y: Obj = {}; y["ok...