• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023-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
16interface GeneratedObjectLiteralInterface_1 {
17    n: number;
18    s: string;
19}
20let o1: GeneratedObjectLiteralInterface_1 = {n: 42, s: "foo"}
21let o2: Object = {n: 42, s: "foo"}
22let o3: object = {n: 42, s: "foo"}
23
24let oo: Object[] = [{n: 1, s: "1"}, {n: 2, s: "2"}]
25
26class C2 {
27    s: string
28    constructor(s: string) {
29        this.s = "s =" + s
30    }
31}
32let o4: C2 = {s: "foo"}
33
34class C3 {
35    readonly n: number = 0
36    readonly s: string = ""
37}
38let o5: C3 = {n: 42, s: "foo"}
39
40abstract class A {}
41let o6: A = {}
42
43class C4 {
44    n: number = 0
45    s: string = ""
46    f() {
47        console.log("Hello")
48    }
49}
50let o7: C4 = {n: 42, s: "foo", f : () => {}}
51
52class Point {
53    x: number = 0
54    y: number = 0
55}
56function id_x_y(o: Point): Point {
57    return o
58}
59
60// Structural typing is used to deduce that p is Point:
61interface GeneratedObjectLiteralInterface_2 {
62    x: number;
63    y: number;
64}
65let p: GeneratedObjectLiteralInterface_2 = {x: 5, y: 10}
66id_x_y(p)
67
68// A literal can be contextually (i.e., implicitly) typed as Point:
69id_x_y({x: 5, y: 10})