Currently, I am working with TypeScript and my main goal is to transform the object structure in ①props into the structure shown in ②.
①
Test {props: {…}}
props:
avatarUrl: "/test.jpg"
id: 1
name: "test"
[[Prototype]]: Object
[[Prototype]]: Object
②
Test
avatarUrl: "/test.jpg"
id: 1
name: "test"
[[Prototype]]: Object
export class Test {
readonly id!: number;
readonly name!: string;
readonly avatarUrl!: string;
constructor(readonly props: TestProps) {
zProps.parse(props);
console.log(props) // ①
props
}
}
export const fetchTest = async (): Promise<Test> => {
const { data } = await apiClient.get("https/test");
return new Test({
avatarUrl: data.avatarUrl,
id: data.id,
name: data.name,
});
};