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 16/*--- 17 desc: 10.04.Interface_Members 18 name: 10.Interfaces/10.04.Interface_Members/interface_with_optional_attributes_0001.sts 19 tags: 20 ---*/ 21 22interface IStudent { 23 name: string; 24 age: int; 25 desc?: string | undefined; 26} 27 28class Student implements IStudent { 29 name: string; 30 age: int; 31 desc?: string | undefined; 32 33 constructor(name: string, age: int, desc: string) { 34 this.name = name; 35 this.age = age; 36 this.desc = desc 37 } 38 39 constructor(name: string, age: int) { 40 this.name = name; 41 this.age = age; 42 } 43} 44 45function main() : void { 46 let s : Student = new Student("Klara", 18, "an excellent student"); 47 let s1 : Student = new Student("Karl", 18); 48 49 assert s.name == "Klara" 50 assert s.age == 18 51 assert s.desc == "an excellent student" 52 assert s1.name == "Karl" 53 assert s1.age == 18; 54 assert s1.desc == undefined; 55} 56