Typescript
[TypeScript] interface object 안 objects들 인터페이스, 배열 안 배열의 인터페이스 만들기
알로호모라
2021. 12. 3. 10:56
반응형
오브젝트 안 오브젝트들 인터페이스로 만들기
{
name: "test",
items: {
"a": {
id: 1,
size: 10
},
"b": {
id: 2,
size: 34
}
}
}
위의 items를 인터페이스로 만들 때 [key: key의 type]을 사용한다.
위의 예제를 인터페이스로 작성할 때 아래처럼 작성한다. "a", "b" 는 string이므로 [key: string] 이렇게!
export interface Item {
id: number;
size: number;
}
export interface Example {
name: string;
items: {
[key: string]: Item
};
}
[ [ {1:1}, {2:2}, {3:3}, {4:4} ], [ {1:1} ], [ {2:2}, {3:3} ] ] 인 경우의 인터페이스 만들기
객체 {1:1} 의 인터페이스를 IObject 라고 하면
IObject[][]
전체 인터페이스는 위와 같다.
Typescript: How do I define interfaces for nested objects?
Assume I have a JSON payload that parses into something like this: { name: "test", items: { "a": { id: 1, size: 10 }, "b": { id...
stackoverflow.com
반응형