如何将接口key: value: string改为[{ [key: string]: string }
How to change the interface key: value: string to [{ [key: string]: string }
我有接口
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 - 适配器工作...)
希望得到您的帮助。非常感谢!
正如错误所说,Index signature is missing in type 'IUser'
所以添加它:
interface IUser {
name: string;
surname: string;
cityLocation: string;
[key: string]: string;
}
我有接口
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 - 适配器工作...)
希望得到您的帮助。非常感谢!
正如错误所说,Index signature is missing in type 'IUser'
所以添加它:
interface IUser {
name: string;
surname: string;
cityLocation: string;
[key: string]: string;
}