我只是学习打字稿,我注意到在按字符串索引时它没有数组的类型安全性。按编号索引时,它按预期工作。有谁解释这个?我怀疑它是一个错误,但我找不到任何有关此行为的信息。感谢
let x : string[] = [];
x[0] = 'test'; // OK, as expected
x[0] = 123; // as expected, error TS2322: Type 'number' is not assignable to type 'string'.
x['hi'] = 123; // OK?? Expected error TS2322 as above