1/* 2* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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*/ 15import { AsyncCallback, Callback } from './../basic'; 16 17declare namespace napitest { 18 export class Image { 19 width: number; 20 height: number; 21 toDataURL(type?: string, quality?: number): string; 22 } 23 24 export class Human { 25 name: string; 26 age: number; 27 } 28 29 // 变换括号位置 30 class Man 31 { 32 name: string; 33 age: number; 34 } 35 36 // 有参构造函数的转换 37 export class Woman { 38 constructor(name_: string, age_: number, isMarried_: boolean); 39 w_name: string; 40 w_age: number; 41 w_isMarried: boolean; 42 } 43 44 export enum LaunchReason { 45 UNKNOWN = 0, 46 START_ABILITY = 1, 47 CALL = 2, 48 CONTINUATION = 3, 49 } 50 51 export class TestClass1 { 52 ahuman: Human; 53 fun1(v: number): number; 54 fun2(numcc: Array<number>, mancc: Human): Human; 55 fun3: (v: number, v1: string, v2: boolean) => boolean; 56 fun4: (mancc: Map<string, string>,v?: string) => Array<number>; 57 fun5: (data: Array<Human>) => Human; 58 fun6: (v: string[], v1: { [key: string]: boolean }) => string[]; 59 fun8: () => void; 60 fun9(manA: Man): string; 61 fun10(v: Image): string; 62 63 //参数为enum 64 fun11(v: LaunchReason): string; 65 fun12(v: TestStatus): string; 66 fun13(v: TestEnumString): string; 67 68 // return value is enum type of defined later 69 // to support 70 // fun14(v: string): ReturnStatus; 71 // fun15(v: string): ReturnEnumString; 72 73 /*fun7: (v: string, v1: LaunchReason) => LaunchReason; --待支持*/ 74 } 75 76 // class 定义在使用之后 begin 77 function func4(v: TestClassLater): string; 78 79 export class TestClassUse { 80 v0: string; 81 // v1: testClassLater; 82 funceUse(n0: TestClassLater): string; 83 } 84 85 export class TestClassLater { 86 v0: string; 87 v1: number; 88 funcLater(n0: number): string; 89 } 90 // class 定义在使用之后 end 91 92 // 数值型枚举 93 export enum TestStatus { 94 UNKNOWN = 0, 95 START_ABILITY = 1, 96 CALL = 2, 97 CONTINUATION = 3, 98 } 99 100 // 字符型枚举 101 export enum TestEnumString { 102 ACTION_HOME = 'ohos.want.action.home', 103 ACTION_DIAL = 'ohos.want.action.dial', 104 ACTION_SEARCH = 'ohos.want.action.search', 105 ACTION_WIRELESS_SETTINGS = 'ohos.settings.wireless', 106 } 107 108 // 数值型枚举 109 export enum ReturnStatus { 110 UNKNOWN = 0, 111 START_RETURN = 1, 112 MIDDLE_RETURN = 2, 113 END_RETURN = 3, 114 } 115 116 // 字符型枚举 117 export enum ReturnEnumString { 118 RETURN_HOME = 'ohos.want.return.home', 119 RETURN_DIAL = 'ohos.want.return.dial', 120 RETURN_SEARCH = 'ohos.want.return.search', 121 RETURN_WIRELESS_SETTINGS = 'ohos.settings.return.wireless', 122 } 123 124 export class TestClass2 { 125 // 函数多参数非嵌套场景 126 func1(name : string, fp3: {nm: string, age: number, flag: boolean}): string; 127 128 // 函数返回值场景 129 func2(input: string): { read: number; written: number; flag: boolean }; 130 131 // Promise返回值逗号场景 132 func3(from: string, to: string): Promise<{result: number, errMsg: string, isT: boolean}>; 133 134 // Promise返回值分号场景 135 func4(from: string, to: string): Promise<{result: number; errMsg: string; isT: boolean}>; 136 137 // class成员方法隐式推导返回值 138 func5(v1: string, v2: number, v3: boolean); 139 } 140 141 // class 成员变量包含enum类型,且class成员方法自引用 142 export enum Type 143 { 144 typeA, 145 typeB, 146 typeC 147 } 148 149 export class Test { 150 type: Type; 151 func(param: Type): boolean; 152 } 153 154 export interface aa { 155 abc: string; 156 def: number; 157 } 158 159 export class Demo { 160 equals(other: Demo): boolean; 161 handleCallback(): void; 162 163 intPro: number; 164 strPro: string; 165 boolPro: boolean; 166 inter: aa; 167 type: Type; 168 } 169 170 function funcTest(v: Type): boolean; // enum为参数 171 function funcTest2(v: Test): boolean; // 包含enum成员变量的 class 为参数 172} 173 174export default napitest; 175