'I want to move the typescript object up one level in the hierarchy
I'm using typescript.
The content of ①props is as follows. I'd like to make it look like ②.
I want to make the object in ① into the object 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,
});
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
