1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Type 'number[]' is not assignable to type '[number, number]' を解決する

Posted at

座標のような、値がちょうど二つ欲しいとき、[number, number]型を指定します。

const map = (center: [number, number]) => {
  ...
}

center[number, number]型 を明示して宣言します。

const center: [number, number] = [10, 20]

map(center)

そうでないと、

const center = [10, 20]  // number[]

map(center)
// Type 'number[]' is not assignable to type '[number, number]'

center は配列として推論されるのでコンパイルに失敗します。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?