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
16interface Z {
17    foo: number;
18}
19
20interface Z1 {
21    foo: number;
22}
23
24
25 // X implements interface Z, which makes relation between X and Y explicit.
26class C implements Z, Z1 {
27     public foo: number
28     public bar: string;
29
30     constructor() {
31        this.foo = 0
32        this.bar = "Class C";
33     }
34 }
35
36 // Y implements interface Z, which makes relation between X and Y explicit.
37 class C2 implements Z, Z1 {
38     public foo: number;
39     public bar: boolean
40
41     constructor() {
42        this.foo = 0;
43        this.bar = true;
44     }
45 }
46
47 let x1: Z = new C()
48 let y1: Z1 = new C2()
49
50console.log("Assign X to Y")
51y1 = x1 // ok, both are of the same type
52
53console.log("Assign Y to X")
54x1 = y1 // ok, both are of the same type
55