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 16type partial_A = Partial<A>; 17 18class A { 19 num_memb: number; 20 str_memb: String = ""; 21 b_memb: B = new B(); 22} 23 24class B { fld: number = 6 } 25class C { c_num_memb: number; } 26class D extends C { d_num_memb: number; } 27 28function main(): void { 29 let part_a_1: Partial<A> = { 30 num_memb: 2.0, 31 str_memb: "part_a_1", 32 b_memb: new B() 33 }; 34 35 assert(part_a_1.num_memb == 2.0); 36 assert(part_a_1.str_memb == "part_a_1"); 37 assert(part_a_1.b_memb?.fld == 6); 38 part_a_1.num_memb = undefined 39 assert(part_a_1.num_memb == undefined); 40 41 let part_a_2: Partial<A> = { 42 num_memb: 4.0, 43 str_memb: "part_a_2" 44 }; 45 46 assert(part_a_2.num_memb == 4.0); 47 assert(part_a_2.str_memb == "part_a_2"); 48 assert(part_a_2.b_memb == undefined); 49 50 let part_a_3: Partial<D> = { d_num_memb: 3.0, c_num_memb: 5.0 }; 51 part_a_3.d_num_memb = undefined 52 assert(part_a_3.c_num_memb == 5.0); 53 assert(part_a_3.d_num_memb == undefined); 54 55 let part_a_4: partial_A = { 56 num_memb: 6.0, 57 str_memb: "part_a_4", 58 b_memb: new B() 59 }; 60 61 assert(part_a_4.num_memb == 6.0); 62 assert(part_a_4.str_memb == "part_a_4"); 63 assert(part_a_4.b_memb?.fld == 6); 64 part_a_4.num_memb = undefined 65 assert(part_a_4.num_memb == undefined); 66} 67