1/* 2 * Copyright (c) 2023 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 */ 15 16export namespace N { 17 export type Generic<T> = T; 18 export type Undef = undefined; 19 export type Any = any; 20 export type Union = number | Any | string; 21 export type UnionWithNull = number | null | Any | string; 22 export type Nullable1 = null | string; 23 export type Nullable2 = string | null; 24 export type StringLitType = "ease-in" | "ease-out" | "ease-in-out"; 25 26 // as field in class 27 export class UserClass1 { 28 static field1: TYPE; 29 } 30 31 // as variable 32 export let GLOB: TYPE; 33 34 // as argument and return value 35 export function func(arg: TYPE): TYPE { 36 return arg; 37 } 38 39 export class UserClass2 { 40 func2(arg: TYPE, arg2: unknown): TYPE { 41 return arg; 42 } 43 } 44 45 export class UserClass3 { 46 // as type argument 47 field3: Generic<TYPE>; 48 // as array type 49 field4: TYPE[]; 50 // as intersection type 51 field5: TYPE[] & Generic<TYPE> & TYPE & undefined; 52 // as union type 53 field6: TYPE[] | Generic<TYPE> | TYPE | undefined; 54 } 55 56 // never type test 57 export function Never(): never { 58 throw new Error(""); 59 } 60 61 // test tuple 62 export function fooTuple(): [string, number] { 63 return ["1", 1]; 64 } 65 66 // test object literal 67 export function fooObject(): { res: string } { 68 return { res: "34" }; 69 } 70 71 // test # private conversion 72 export class UserClass4 { 73 #field1: number = 1; 74 #foo(): void {} 75 private field2: number = 1; 76 private baz(): void {} 77 readonly field3: number = 1; 78 } 79} 80 81function freeFunction(): number { 82 return 44; 83} 84 85export function freeExportFunction(): number { 86 return 4; 87} 88 89export function optional1(a: number, arg?: string): void {} 90 91export function optional2(a?: number, arg?: string): void {} 92 93export function optional3(a: number | null, arg?: string): void {} 94 95export function optional4(a?: number | string, arg?: string): void {} 96 97export function optional5(a?: boolean, arg?: string): void {} 98 99export function optional6(a?: N.UserClass1, arg?: string): void {} 100 101export interface Optional1 { 102 a?: string; 103 b?: number; 104 c?: boolean; 105} 106 107export class Optional2 { 108 a?: string = ""; 109 b?: number = 1; 110 c?: boolean = undefined; 111} 112 113export interface D { 114 foo(): this; 115 foo2(): D; 116} 117 118export class Box { 119 Set(value: string): this { 120 return this; 121 } 122} 123 124export type s = { ss: number; kk: string }; 125export type S = s["ss"]; 126export type ss = { ff: s; 2: s }; 127 128export type X<T> = T extends number ? T : never; 129export type XX<T> = T extends number ? T : number; 130export type Y<T> = T extends number ? T : never; 131export type YY<T> = T extends Array<infer Item> ? Item : never; 132 133export class Q { 134 static d: number = 1; 135 static d2: typeof Q.d; 136 137 static j: unknown; 138 static j2: typeof Q.j; 139} 140 141export interface NewCtor { 142 new (arg: string): NewCtor; 143 foo(): this; 144 foo2(): D; 145} 146 147export type OptionsFlags<Type> = { 148 [Property in keyof Type]: boolean; 149}; 150 151export type MappedTypeWithNewProperties<Type> = { 152 [Properties in keyof Type as number]: Type[Properties]; 153}; 154 155export function calculateMyReturnType() { 156 return 1; 157} 158 159export class Point { 160 x: number = 1; 161 y: number = 2; 162} 163 164export type PointKeys = keyof Point; 165 166export type SomeConstructor = { 167 new (s: string): number; 168}; 169 170export interface DescribableFunction { 171 description: string; 172 (someArg: number): string; // call signature 173} 174 175export class Person { 176 constructor(name: string, age: number) {} 177} 178export type PersonCtor = new (name: string, age: number) => Person; 179 180export function rdonly1(arr: readonly string[]) { 181 arr.slice(); 182} 183 184export type A = Awaited<Promise<string>>; 185export type B = Awaited<Promise<Promise<number>>>; 186export type C = Awaited<boolean | Promise<number>>; 187export type Part = Partial<Point>; 188export type Req = Required<Part>; 189export type Rdonly = Readonly<Point>; 190export type Rec = Record< 191 "miffy" | "boris" | "mordred", 192 { 193 age: number; 194 breed: string; 195 } 196>; 197export type TodoPreview = Pick< 198 { 199 title: string; 200 description: string; 201 completed: boolean; 202 }, 203 "title" | "completed" 204>; 205export type TodoInfo = Omit< 206 { 207 title: string; 208 description: string; 209 completed: boolean; 210 createdAt: number; 211 }, 212 "completed" | "createdAt" 213>; 214export type T3 = Exclude< 215 { kind: "circle"; radius: number } | { kind: "square"; x: number }, 216 { kind: "circle" } 217>; 218export type T2 = Extract< 219 { kind: "circle"; radius: number } | { kind: "square"; x: number }, 220 { kind: "circle" } 221>; 222export type T0 = NonNullable<string | number | undefined>; 223export type T1 = NonNullable<string[] | null | undefined>; 224export type TT0 = Parameters<() => string>; 225export type TT1 = Parameters<(s: string) => void>; 226export type TT2 = Parameters<<T>(arg: T) => T>; 227export type TT4 = Parameters<any>; 228export type TT5 = Parameters<never>; 229export type TC0 = ConstructorParameters<ErrorConstructor>; 230export type TC1 = ConstructorParameters<FunctionConstructor>; 231export type TC2 = ConstructorParameters<RegExpConstructor>; 232export type TC4 = ConstructorParameters<any>; 233export type TR0 = ReturnType<() => string>; 234export type TR1 = ReturnType<(s: string) => void>; 235export type TR2 = ReturnType<<T>() => T>; 236export type TR3 = ReturnType<<T extends U, U extends number[]>() => T>; 237export type TR5 = ReturnType<any>; 238export type TR6 = ReturnType<never>; 239export type TI1 = InstanceType<any>; 240export type TI2 = InstanceType<never>; 241export type TTP = ThisParameterType<Array<Number>>; 242export type TOP = OmitThisParameter<Array<Number>>; 243export type TTT = ThisType<Array<Number>>; 244import m = require("mod"); 245export interface F extends m {} 246import { default as d } from "def"; 247export interface DD extends d {} 248import { default as dd, KK, HH as H, default as ddd } from "def"; 249export interface DD extends dd {} 250export interface DD extends KK {} 251export interface DD extends H {} 252export interface DD extends ddd {} 253export namespace KK { 254 import { default as d } from "def"; 255 export interface DD extends d {} 256 import { default as dd, KK, HH as H, default as ddd } from "def"; 257 export interface DD extends dd {} 258 export interface DD extends KK {} 259 export interface DD extends H {} 260 export interface DD extends ddd {} 261} 262import { LKL } from "def.js"; 263export interface DD extends LKL {} 264import { LL } from "def.json" assert { type: "json" }; 265export interface DD extends LL {} 266import { default as LLL } from "def.json" assert { type: "json" }; 267export interface DD extends LLL {} 268import type { TType } from "def"; 269export interface DD extends TType {} 270export class KeyA { 271 [key: string]: boolean; 272} 273export interface KeyB { 274 [key: string]: boolean; 275} 276export type KeyC = { 277 [key: string]: boolean; 278}; 279