function f([a,b,c]) {
// this works but a,b and c are any
}
そのようなことを書くことは可能ですか?
function f([a: number,b: number,c: number]) {
// being a, b and c typed as number
}
function f([a,b,c]) {
// this works but a,b and c are any
}
そのようなことを書くことは可能ですか?
function f([a: number,b: number,c: number]) {
// being a, b and c typed as number
}
はい、そうです。TypeScript では、タプルを作成するという単純な方法で配列の型を使用してこれを行います。
type StringKeyValuePair = [string, string];
配列に名前を付けることで、必要なことを実行できます。
function f(xs: [number, number, number]) {}
しかし、interal パラメータには名前を付けません。もう 1 つの可能性は、ペアによる分割を使用することです。
function f([a,b,c]: [number, number, number]) {}