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 16interface A{ 17 field1:number; 18} 19 20class B{ 21 field1:number = 0; 22} 23 24abstract class C{ 25 field1:number = 0; 26} 27 28abstract class D{ 29 field1?:number; 30 field2?:string; 31 field3:A = {field1:0}; 32 field4:B = {field1:0}; 33 field5:C = {field1:0}; 34} 35 36function main(){ 37 let x:D = {field1:1000,field2:"some str",field3:{field1:10}} 38 assertEQ(x.field1, 1000) 39 assertEQ(x.field2, "some str") 40 assertEQ(x.field3.field1, 10) 41 42 let x2:B = new B(); 43 x2.field1 = 10; 44 let x3:D = {field4:x2} 45 assertEQ(x3.field4.field1, 10) 46 47 let x4:B = {field1:10} 48 let x5:D = {field4:x4} 49 assertEQ(x5.field4.field1, 10) 50 51 let x6:D = {field5:{field1:10}} 52 assertEQ(x6.field5.field1, 10) 53} 54