中級 › readonly配列にpushしようとするとdoes not exist on typeになる理由 › パターン4
readonly配列にpushしようとするとdoes not exist on typeになる理由
readonly number[]のように宣言した配列型には、push・pop・splice等の破壊的(要素を変更する)メソッドがそもそも型として存在しません。
1 function tagAll(items: readonly string[]): void { 2 items.______("z"); ^ 3 console.log(items); 4 } 5 tagAll(["a", "b"]);
main.ts(2,9): error TS2339: Property 'push' does not exist on type 'readonly string[]'.
空欄を埋めてコンパイルを通す
readonly string[]にはpushのような破壊的メソッドは型として存在しません。
次の問題