1/* 2 * Copyright (c) 2024 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 16let x!: number; 17initializeX(); 18console.log(x + x); 19 20function initializeX() { 21 x = 10; 22} 23 24let y: number; 25initializeY(); 26 27console.log(y! + y!); // it's not a definite assignment assertion, it's the 'Ensure Not-Null expression', see 7.16 ArkTS spec 28function initializeY() { 29 y = 20; 30} 31 32class ArticleMeta { 33 private wordsPerMinute!: number; 34 private secondsPerImage: number; 35 36 constructor(wordsPerMinute: number) { 37 this.secondsPerImage = 15; 38 } 39} 40 41class Person { 42 name: string = "" 43 age: number = 0 44 location: string = "" 45} 46 47type OptionalPerson = Person | undefined 48let persons : Record<string, OptionalPerson> = { 49 "Bob": { 50 name: "Bob", 51 age: 48, 52 location: "New York" 53 } 54} 55console.log(persons["Bob"]!.age) 56