我有一個非常簡單的打字稿定義爲「字典」,它看起來是這樣的:打字稿字典不履行
interface IDictionary<T> {
[key: string]: T;
}
然後我用這個接口的另一個接口定義,像這樣:
interface IGatewayInput {
queryParameters: IDictionary<string>;
body?: string;
}
我然後有其接收IGatewayInput
的函數:
doSomething(input: IGatewayInput) {
if(input.queryParameters.oauth_token) {
// ....
}
}
但WH ILE我期望的字典,讓「queryParameters」有任何鍵值,而不是我得到以下錯誤:
error TS2339: Property 'oauth_token' does not exist on type 'IDictionary'.'
我在做什麼錯?我認爲我的定義將允許任何基於字符串的鍵值?
這會導致相同的錯誤 – ken
我不知道你是如何測試的,但是這段代碼絕對必須工作!你正在使用什麼打字稿編譯器版本? – devlux
vs-code和TS 2.0.9 – ken