• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
16class C1 {
17    n: number = 0
18    s: string = ""
19}
20
21let o1: C1 = {n: 42, s: "foo"}
22let o2: C1 = {n: 42, s: "foo"}
23let o3: C1 = {n: 42, s: "foo"}
24
25let oo: C1[] = [{n: 1, s: "1"}, {n: 2, s: "2"}]
26
27class C2 {
28    s: string
29    constructor(s: string) {
30        this.s = "s =" + s
31    }
32}
33let o4 = new C2("foo")
34
35class C3 {
36    n: number = 0
37    s: string = ""
38}
39let o5: C3 = {n: 42, s: "foo"}
40
41abstract class A {}
42class C extends A {}
43let o6: C = {}
44
45class C4 {
46    n: number = 0
47    s: string = ""
48    f() {
49        console.log("Hello")
50    }
51}
52let o7 = new C4()
53o7.n = 42
54o7.s = "foo"
55
56class Point {
57    x: number = 0
58    y: number = 0
59}
60
61function id_x_y(o: Point): Point {
62    return o
63}
64
65let p: Point = {x: 5, y: 10}
66id_x_y(p)
67
68id_x_y({x: 5, y: 10})