TypeScript tuple 元组 All In One
TypeScript tuple 元组 All In One
元组类型允许您用固定数量的元素表示数组,这些元素的类型是已知的,但不必相同。
fixed types
let tuple: [string, number, boolean];
tuple = ["string", 1, true];
const tuple: [string, number, boolean] = ["string", 1, true];
demos
"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)
TypeScript errors
and how to fix them
可变参数 / 不定参数
(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!
refs
可变参数 / 不定参数
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-0.html#variadic-tuple-types
https://www.typescriptlang.org/docs/handbook/basic-types.html#tuple
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/13882311.html
未经授权禁止转载,违者必究!