• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023-2023 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    bar: string;
22}
23
24 // X implements interface Z, which makes relation between X and Y explicit.
25 class C implements Z, Z1 {
26     public foo: number
27     public bar: string;
28
29     constructor() {
30        this.foo = 0
31        this.bar = "Class C";
32     }
33 }
34
35 // Y implements interface Z, which makes relation between X and Y explicit.
36 class C2 implements Z, Z1 {
37     public foo: number;
38     public bar: string;
39
40     constructor() {
41        this.foo = 0;
42        this.bar = "Class C2";
43     }
44 }
45
46 let x1: Z = new C()
47 let y1: Z1 = new C2()
48
49console.log("Assign X to Y")
50y1 = x1 // ok, both are of the same type
51
52console.log("Assign Y to X")
53x1 = y1 // ok, both are of the same type
54