1/* 2 * Copyright (c) 2022-2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15export type MyTuple=[number,string,boolean]; 16export let tuple:MyTuple=[6,'abc',true]; 17 18export let tupleObject: [number, number]=[0x55aa, 0x7c00]; 19 20export function example(args: [string, number]): [boolean] { 21 return [true]; 22} 23 24export const value: [string, number] = ['hello', 42]; 25 26export interface User { 27 info: [string, number]; 28} 29 30export class MyClass { 31 data: [number, string]; 32 33 constructor() { 34 this.data = [0, '']; 35 } 36} 37 38export const [a, b]: [string, number] = ['hello', 42]; 39 40export type Result = [string, number] | null; 41 42export type Mapped<T> = { [K in keyof T]: [T[K], string] }; 43export type Test = Mapped<{ a: number; b: boolean }>; 44 45export type NestedTuple = [[number, string], [boolean, object]]; 46 47export type Mixed = [number, string][] | [string, number]; 48 49export async function getData(): Promise<[string, number]> { 50 return ['data', 123]; 51} 52 53export type WithDefault<T = [string, number]> = T; 54 55export type Example = WithDefault; 56 57export interface Options { 58 config?: [string, number]; 59} 60 61export const user = { 62 name: 'Alice', 63 metadata: [1, 'info'] 64}; 65 66export type IfTuple<T> = T extends [any, any] ? true : false; 67 68export type A = IfTuple<[number, string]>; 69export type B = IfTuple<string[]>; 70 71export type ReadonlyTuple = readonly [string, number]; 72 73