如何使用打字稿将数组转换为记录?
我有一个人。 array< person>
export const peopleExample : Array<Person> = [
{
name: 'Leo'
age: 12
},
{
name: 'Donna'
age: 20
}
]
我希望将其转换为MockedResponse&lt; string&lt; string,any ny&gt; []
export const generateMockPerson = () : MockedResponse<Record<string,any>[] => {
return peopleExample.reduce((prev, next) => {
let myRecord = {};
let keys = "keys";
myRecord[keys].add(next);
return myRecord;
}, [] as MockedResponse<Record<string, any>>[]);
};
模拟响应是
export interface MockedResponse<TData = Record<string, any>> {
request: GraphQLRequest;
result?: FetchResult<TData> | ResultFunction<FetchResult<TData>>;
error?: Error;
delay?: number;
newData?: ResultFunction<FetchResult>;
}
我一直在尝试使用还原器,但我不是成功的。 感谢您的帮助。
I have an array of person. Array<Person>
export const peopleExample : Array<Person> = [
{
name: 'Leo'
age: 12
},
{
name: 'Donna'
age: 20
}
]
I wish to convert it to MockedResponse<Record<string,any>[]
export const generateMockPerson = () : MockedResponse<Record<string,any>[] => {
return peopleExample.reduce((prev, next) => {
let myRecord = {};
let keys = "keys";
myRecord[keys].add(next);
return myRecord;
}, [] as MockedResponse<Record<string, any>>[]);
};
Mocked Response is
export interface MockedResponse<TData = Record<string, any>> {
request: GraphQLRequest;
result?: FetchResult<TData> | ResultFunction<FetchResult<TData>>;
error?: Error;
delay?: number;
newData?: ResultFunction<FetchResult>;
}
I have been trying to use reducers, but i'm not successful.
Would appreciate the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论