type Foo = {
    isSubscribed: boolean
    [field: string]: string
}


이렇게 쓰면 isSubscribed 가 index signaure 형식에 맞지 않아서 적용할 수가 없다.


type Foo = {
    isSubscribed: boolean
} & {
    [field: string]: string
}


intersection으로는 선언이 가능하다. 


const bar: Foo = {
    isSubscribed: true,
    name: "wook"
}


하지만 이런식으로 변수 설정을 할 수 없다.


const bar: Foo = Object.assign(
    {
        isSubscribed: true,
    },
    {
        name: "wook"
    }
);


이런식으로 할당하던지


declare const bar: Foo;

bar.isSubscribed = true;
bar.name = "wook";


이런식으로 선언해야 한다.

+ Recent posts