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 16class A{ 17 field1:number = 10; 18 foo(){} 19 private field2:number = 20; 20 private foo2(){} 21 protected field3:number = 30; 22 protected foo3(){} 23} 24 25class B extends A{ 26 bfield1:number = 10; 27 bfoo(){} 28 private bfield2:number = 20; 29 private bfoo2(){} 30 protected bfield3:number = 30; 31 protected bfoo3(){} 32} 33 34function main():void{ 35 let c1:keyof B = "field1" 36 let c2:keyof B = "foo" 37 let c3:keyof B = /* @@ label1 */"field2" 38 let c4:keyof B = /* @@ label2 */"foo2" 39 let c5:keyof B = /* @@ label3 */"field3" 40 let c6:keyof B = /* @@ label4 */"foo3" 41 let c7:keyof B = "bfield1" 42 let c8:keyof B = "bfoo" 43 let c9:keyof B = /* @@ label5 */"bfield2" 44 let c10:keyof B = /* @@ label6 */"bfoo2" 45 let c11:keyof B = /* @@ label7 */"bfield3" 46 let c12:keyof B = /* @@ label8 */"bfoo3" 47} 48 49/* @@@ label1 Error TypeError: Type '"field2"' cannot be assigned to type '"bfoo"|"bfield1"|"foo"|"field1"' */ 50/* @@@ label2 Error TypeError: Type '"foo2"' cannot be assigned to type '"bfoo"|"bfield1"|"foo"|"field1"' */ 51/* @@@ label3 Error TypeError: Type '"field3"' cannot be assigned to type '"bfoo"|"bfield1"|"foo"|"field1"' */ 52/* @@@ label4 Error TypeError: Type '"foo3"' cannot be assigned to type '"bfoo"|"bfield1"|"foo"|"field1"' */ 53/* @@@ label5 Error TypeError: Type '"bfield2"' cannot be assigned to type '"bfoo"|"bfield1"|"foo"|"field1"' */ 54/* @@@ label6 Error TypeError: Type '"bfoo2"' cannot be assigned to type '"bfoo"|"bfield1"|"foo"|"field1"' */ 55/* @@@ label7 Error TypeError: Type '"bfield3"' cannot be assigned to type '"bfoo"|"bfield1"|"foo"|"field1"' */ 56/* @@@ label8 Error TypeError: Type '"bfoo3"' cannot be assigned to type '"bfoo"|"bfield1"|"foo"|"field1"' */ 57