📜  typescriprt 指定键的类型 - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:23.510000             🧑  作者: Mango

代码示例1
var stuff: { [key: string]: string; } = {};
stuff['a'] = ''; // ok
stuff['a'] = 4;  // error

// ... or, if you're using this a lot and don't want to type so much ...
interface StringMap { [key: string]: string; }
var stuff2: StringMap = { };
// same as above