9cubed
ブログ | Tailwind | Vite | Python | Node.js | Linux | PowerShell | その他 | 将棋ウォーズ | 歌の練習
< 前の記事

TypeScript - 列挙型(enum)

次の記事 >

TypeScript - 既存の型の別名の付与(type)

TypeScript

TypeScript - タプル型

公開日:2019-01-15
更新日:2019-05-14

1. 概要

タプル型の使い方です。
関数の戻り値の型として使用すると、複数の戻り値を返すことができます。

//宣言
let 変数名: [型, 型, 型, ・・・];

//タプルのまま代入
変数名 = [値, 値, 値, ・・・ ];

//各値を各変数に代入
[変数名, 変数名, 変数名, ・・・ ] = [値, 値, 値, ・・・ ]

2.1 サンプル

let data: [string, number, number];

data = ["apple", 10, 20];

console.log(data[0]); //apple
console.log(data[1]); //10
console.log(data[2]); //20

console.log(data.length); //3

apple
10
20
3

2.2 サンプル

関数の戻り値にタプルを使用して、複数の戻り値を返します。

function getSize(): [number, number] {
	return [10, 20];
}

let width : number;
let height: number;

[width, height] = getSize();
console.log(width);  //10
console.log(height); //20


< 前の記事

TypeScript - 列挙型(enum)

次の記事 >

TypeScript - 既存の型の別名の付与(type)

YouTube X

新着一覧

  • SCSS のインストールVite
  • Tailwind CSS のプロジェクトの作成Tailwind
  • TypeScriptのプロジェクトの作成Vite
  • Flask のインストールと動作確認Python
  • 簡易Webサーバーの作成Python
  • pipeline で文章の生成Python
  • pipeline で文章の要約Python
  • 音声から文字起こしPython
  • Node.js のインストールNode.js
  • .ps1(PowerShellスクリプト)を実行可能にするPowerShell

アーカイブ

  • 2025/12
  • 2025/11
  • 2025/10
  • 2025/09
  • 2025/08

以前のカテゴリー一覧

  • CakePHP3
  • CentOS7
  • HTML・CSS・JavaScript
  • Haskell
  • JavaScript
  • Kotlin
  • Laravel5
  • PHP
  • Python
  • Ruby
  • RubyOnRails5
  • TypeScript
  • Vue.js
  • Webサーバ講座
  • Webプログラミング講座
  • jQuery
  • linux
  • パソコン講座
  • ブログ
  • プログラミング講座
  • メモ帳作成講座
  • 数学

Copyright © 9cubed. All Rights Reserved.

プライバシーポリシー 利用規約
▲