元组一章

Author: guda-artCreated Oct 11, 2022Updated Oct 11, 2022

也可以只赋值其中一项:

let tom: [string, number];
tom[0] = 'Tom';

编译时不报错, 也能通过类型检查, 但是tom[0]是undefined,, 所以运行时会报错 ts-node .ts或node .js都会报错

Source: xcatliu/typescript-tutorial