TypeScript tuple 元组

TypeScript tuple 元组

元组类型允许您用固定数量的元素表示数组,这些元素的类型是已知的,但不必相同。


"use strict";

/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright xgqfrms
 * @created 2020-10-21
 * @modified
 *
 * @description
 * @augments
 * @example
 * @link
 *
 */

const log = console.log;

// 元组
let tuple: [string, number, boolean];

tuple = ["string", 1, true];
// tuple = ["string", 1];
// tuple = ["string", "1", false];

log(`tuple =`, tuple)

refs

https://www.typescriptlang.org/docs/handbook/basic-types.html#tuple



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章