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 */ 15 16import { Something, SomethingFactory, SomethingBar, Bar, Select } from "./oh_modules/ohos_factory"; 17 18class C { 19 static a = 5 20 static b = 8 21} 22 23namespace H { 24 export class G {} 25} 26 27let c = C 28c = C 29let g = H.G 30g = H.G 31 32let ca = C.a 33let cb = C.b 34 35let cc = new C() 36let gg = new H.G() 37 38function foo1(arg: typeof C) {} 39foo1(C) 40 41function foo2(arg: C) { 42 return C 43} 44 45function foo3(arg: typeof H.G) {} 46foo3(H.G) 47 48function foo4(arg: H.G) { 49 return H.G 50} 51 52class A {} 53interface B {} 54interface I {} 55class CC extends A implements I, B {} 56 57class D { 58 constructor(arg: typeof C) {} 59} 60new D(C) 61 62type X = D; 63 64namespace test1 { 65 class SomethingFoo extends Something { } 66 namespace NS { export class SomethingFoo extends Something { } } 67 68 let fact = SomethingFactory.getInstance(); 69 70 let x1 = fact.create1(SomethingFoo).beep(); 71 let x2 = fact.create1(SomethingBar).beep(); 72 let x3 = fact.create1(NS.SomethingFoo).beep(); 73 74 let x4 = fact.create2({ o: SomethingFoo }); 75 let x5 = fact.create2({ o: SomethingBar }); 76 let x6 = fact.create2({ o: NS.SomethingFoo }); 77 78 let x7 = fact.create3(() => SomethingFoo); 79 let x8 = fact.create4(() => SomethingFoo); 80 81 let x9 = new Bar(SomethingFoo); 82} 83 84enum Color { WHITE, BLUE, RED }; 85let color: Color = Color.RED; 86 87for (let item = 0; item < Object.keys(Color).length; item++) { 88 console.log(item); 89} 90 91foo2(() => C); 92 93export { C as H }; 94 95// #14228 96let data = new Select<Object>().from(C).eq('key').query(C); // Ok 97invalid_func(C); // Ok 98let a: any; 99a.foo(C); // Ok 100 101let col = 'WHITE'; 102console.log(Color[col]) 103 104// #14184 105namespace NS { 106 export enum E { 107 A = 'A', 108 B = 'B', 109 C = 'C' 110 } 111} 112 113let s: string = 'B'; 114let s2: string = NS.E[s]; 115 116for (let item = 0; item < Object.keys(NS.E).length; item++) { 117 console.log(item); 118} 119 120/** 121 * {@link C} - should not report error 122 */ 123class JSDocClass {} 124 125function classAsObject(x: any): void {} 126 127classAsObject(Object); 128classAsObject(Function); 129classAsObject(String); 130classAsObject(Boolean); 131classAsObject(Number); 132classAsObject(Math); 133classAsObject(Date); 134classAsObject(RegExp); 135classAsObject(Error); 136classAsObject(EvalError); 137classAsObject(RangeError); 138classAsObject(ReferenceError); 139classAsObject(SyntaxError); 140classAsObject(TypeError); 141classAsObject(URIError); 142classAsObject(AggregateError); 143classAsObject(JSON); 144classAsObject(Array); 145classAsObject(ArrayBuffer); 146classAsObject(DataView); 147classAsObject(Int8Array); 148classAsObject(Uint8Array); 149classAsObject(Uint8ClampedArray); 150classAsObject(Int16Array); 151classAsObject(Uint16Array); 152classAsObject(Int32Array); 153classAsObject(Uint32Array); 154classAsObject(Float32Array); 155classAsObject(Float64Array); 156classAsObject(Map); 157classAsObject(WeakMap); 158classAsObject(Set); 159classAsObject(WeakSet); 160classAsObject(Promise); 161classAsObject(Proxy); 162classAsObject(Symbol); 163classAsObject(SharedArrayBuffer); 164classAsObject(Atomics); 165classAsObject(BigInt); 166classAsObject(BigInt64Array); 167classAsObject(BigUint64Array); 168classAsObject(WeakRef); 169classAsObject(FinalizationRegistry); 170 171const aggrErr = AggregateError([new Error()]); 172const array = Array<number>(10); 173const bi = BigInt(10); 174const bool = Boolean('true'); 175const date = Date(); 176const err = Error('message'); 177const evalErr = EvalError('message'); 178const func = Function('console.log(1)'); 179const num = Number('10'); 180const obj = Object(); 181const rangeErr = RangeError('message'); 182const refErr = ReferenceError('message'); 183const regex = RegExp('abc'); 184const str = String('value'); 185const sym = Symbol('symbol1'); 186const syntaxErr = SyntaxError('message'); 187const typeErr = TypeError('message'); 188const uriErr = URIError('message'); 189 190let aaa4 = typeof DataView; 191 192let obj = new Object(); 193switch (obj) { 194 case Object: 195 console.log('A'); 196 break; 197 default: 198 console.log('F'); 199} 200 201function parse(type: "number" | "boolean", value: string): number | boolean { 202 return type === "number" ? Number(value) : value === "true"; 203} 204function format(input: string | number): string[] | number[] { 205 return typeof input === "string" ? input.split("") : input.toString().split("").map(Number); 206} 207 208let version: string = "1.2" 209let a1 = version.split('.').map(Number); 210 211let version2: string = "1.2" 212let a2 = version2.split('.').map(String); 213 214let version3: string = "1.2" 215let a3 = version3.split('.').map(Boolean);