• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 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
16// TypeScript: treats 'n' as having type number
17// ArkTS: treats 'n' as having type int to reach max code performance
18let a = 1;
19
20a = 1; // OK
21a = 1.5; // CTE in ArkTS: Type 'double' can't be assigned to type 'int'
22
23a += 1; // OK
24a += 1.5; // ArkTS: Result is integer value
25
26console.log(a + 1); // OK
27console.log(a - 0.5); // OK
28console.log(a / 2); // ArkTS: integer division is used, result is integer value
29console.log(a / 2.5); // OK
30console.log(2 / a); // ArkTS: integer division is used, result is integer value
31console.log(2.5 / a); // OK
32
33let b: number = 1;
34a = b; // CTE in ArkTS: Type 'double' can't be assigned to type 'int'
35a += b; // ArkTS: Result is integer value
36console.log(a + b); // OK
37console.log(a / b); // OK
38
39let c = 1.5;
40a = c; // CTE in ArkTS: Type 'double' can't be assigned to type 'int'
41a += c; // ArkTS: Result is integer value
42console.log(a + c); // OK
43console.log(a / c); // OK
44
45let d = 2;
46a = d; // OK
47a += d; // OK
48console.log(a + d); // OK
49console.log(a / d); // ArkTS: integer division is used, result is integer value
50
51let n = 2;
52
53let f: number = 1
54
55let g = [1, 2, 3]
56
57let x!: number
58
59let t8 = Infinity
60
61let t9 = -Infinity;
62
63let t10 = NaN;
64
65let t11 = Number.MAX_VALUE;
66
67let t12 = Number.MIN_VALUE;
68
69let o:number = 123;
70
71const oo:number = 123;
72
73let o2 = o;
74
75let o3 = oo;
76
77class A{
78   a = 1;
79   constructor() {
80  }
81}
82
83let t2 = +123;
84
85let t3 = -234;
86
87let num = Math.floor(4.8); // num 可能是 int
88
89let value = parseInt("42"); // value 可能是 int
90
91
92function multiply(x = 2, y = 3) {
93 return x * y;
94}
95
96function divide(x: number, y: number) {
97  return x / y;
98}
99
100function identity<T>(value: T): T {
101  return value;
102}
103identity(42);
104
105let an_array = [1,2,3]
106
107let g = an_array[]
108
109const a = 1
110
111enum Test {
112  A = 1,  // 显式赋值为 1
113  B = 2   // 显式赋值为 2
114}
115const test = Test.A;
116
117@Entry
118@Component
119struct Index2 {
120  @State message: string = 'Hello World';
121  readonly c1 = 1; // int
122  readonly c4 = 1.7; // float
123  readonly c5 = 0x123; // 16进制
124  readonly c6 = 0o123; //8进制
125  readonly c7 = 0b101; //2进制
126  readonly c8 = [1,2,3]
127
128build() {
129    RelativeContainer() {
130      Text(this.message)
131        .onClick(() => {
132        })
133    }
134  }
135}
136
137const c1 = 1;
138
139export class G{
140  readonly a5 = 4;
141}
142
143const fingerprintPositionY = AppStorage.get<number>(FingerprintConstants.COORDINATE_Y_OF_FINGERPRINT_UD_SCREEN_IN_PX) ?? 0;
144
145private doCloseFolderBackgroundAnimation(): void {
146    openFolderLayout.getGridSwiperLayout().bgHeight = openFolderLayout.getBackgroundLayout().closedHeight;
147    openFolderLayout.getGridSwiperLayout().bgWidth = openFolderLayout.getBackgroundLayout().closedWidth;
148
149    let pos = [-1, -1];
150    pos = folderLayoutUtil.getFolderComponentCenterPosition(FolderData.getInstance().getOpenedFolder());
151    let editModeTranslateY = this.getEditModeTranslateY(pos);
152    if (pos.length > 1) {
153      let translateXForScreenSplit: number = AppStorage.get<number>('translateXForScreenSplit') ?? 0 as number;
154      let screenWidth: number = AppStorage.get<number>('screenWidth') as number;
155      let screenHeight: number = AppStorage.get<number>('screenHeight') as number;
156      if (screenWidth > screenHeight) {
157        log.showInfo('doCloseFolderBackgroundAnimation screenWidth: ' + screenWidth + ', height: ' + screenHeight);
158        screenWidth = screenHeight;
159      }
160      openFolderLayout.getGridSwiperLayout().bgTranslateX = pos[0] - screenWidth / 2 + translateXForScreenSplit;
161      openFolderLayout.getGridSwiperLayout().bgTranslateY = pos[1] + editModeTranslateY -
162        openFolderLayout.getBackgroundLayout().closedHeight * 0.5 - openFolderLayout.getBackgroundLayout().openedMargin;
163    }
164}
165
166let f = 0.0;
167let b5: number = 0;
168f = b5; // OK
169
170let e = 0.0;
171let g1: number = 0;
172
173e += g1; // OK
174e -= g1; // OK
175e *= g1; // OK
176e /= g1; // OK
177e <<= g1; // OK
178e >>= g1; // OK
179e &= g1; // OK
180e = e & 3; // OK
181e = e | 3; // OK
182let arr1 = [1,2,3]
183e += arr1[0]; // OK
184
185let a = 0.0;
186a = fun1();
187a = fun2()!;
188
189function fun1():number{
190  return 1;
191}
192
193function fun2():number|undefined{
194  return 1;
195}
196
197import { ArrayList } from "@kit.ArkTS";
198
199let arr = new ArrayList<number>()
200for (let i:number = 0; i < 100; i++) {
201  arr.add(i)
202}
203let cancelIds:ArrayList<number> = arr.subArrayList(6, 86)
204let a: Array<number> = Array.from(cancelIds)
205let arr1: Array<number> = Array.from(new ArrayList<number>())
206
207let a:number = 0.000;
208
209const b:number = 0.000;
210
211export enum WalletStageValue {
212  DEFAULT = 0,
213  SWIPE_INIT = -1,
214  SELECT_CARD = 1,
215  SWIPE_DOING = 2,
216  SWIPE_SUCCEED = 3,
217  SWIPE_FAILED = 4,
218  SWIPE_FINISHED = 5,
219}
220
221export enum AnimationStage {
222  INIT = 0,
223  ENTER = 1,
224  ROTATING = 2,
225  EXIT_START = 3,
226  EXIT_END = 4,
227}