我有界面
IUser {
name: string;
surname: string;
cityLocation: string;
}
該值將是
const user: IUser = {
"name": "John";
"surname": "Smith";
"cityLocation": "LA";
}
我有配接器,他們有接收的方法
function adapter(columns: { [key: string]: string }) {...}
當我嘗試這樣做時:
adapter(user);
我有錯誤:
Argument of type 'IUser' is not assignable to parameter of type '{ [key: string]: string; }'. Index signature is missing in type 'IUser'.
我該如何解決?
(有趣,但是當我不使用簽名 IUser 物件用戶時 - 配接器作業......)
希望得到您的幫助。大謝謝!
uj5u.com熱心網友回復:
正如錯誤所說,Index signature is missing in type 'IUser'所以添加它:
interface IUser {
name: string;
surname: string;
cityLocation: string;
[key: string]: string;
}
游樂場鏈接
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/418885.html
標籤:
