typescript interfaceのプロパティを追加する

typescript interfaceのプロパティを追加する

typescriptで、interfaceのプロパティを追加するサンプルコード記述してます。typescriptのバージョンはVersion 4.1.2となります。

環境

  • OS windows10 64bit
  • typescript Version 4.1.2

プロパティ追加

interfaceのプロパティは、以下のようにすると追加することが可能です。

interface hoge {
    num: number;
    str: string;
}

interface hoge {
    arr: number[] // 追加
}

let h: hoge = { num: 10, str: 'mebee', arr: [1, 2, 3] }

console.log(h.num) // 10
console.log(h.str) // mebee
console.log(h.arr) // [ 1, 2, 3 ]