1/*
2 * Copyright (c) 2022-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
17var obj1: { c: number };
18var obj2: { a: number, b: string } | { a: number, b: string, c: number } = { a: 5, b: "foo", ...obj1 };
19obj2 = { a: 2, b: "bar", c: 3 };
20
21var obj3: {} = {};
22var obj4: { a: typeof obj3, b?: { a: number, b?: string } } = { a: {}, b: { a: 5 } };
23obj4 = { a: {}, b: { a: 5, b: "foo" } };
24obj4 = { a: {} };
25
26var obj5: { a: { a: number, b: string }, b: { a: boolean } } = { a: { a: 5, b: "foo" }, b: { a: true } };
27var obj6: { a(a: number, b: string): number, b(): boolean };
28obj6 = { a: function (a: number, b: string): number { return 12; }, b: function () { return true } };
29
30var obj7: {} | { a: number } | { a: string, b: number } | { a: boolean, b: string, c: number };
31obj7 = {};
32obj7 = { a: 5 };
33obj7 = { a: "foo", b: 5 };
34obj7 = { a: true, b: "foo", c: 5 };
35
36var obj8 = { ...obj6 };
37obj8 = obj6;
38obj8 = { a: function (a: number, b: string): number { return 12; }, b: function () { return true } };
39
40var obj9: { 5: number, "foo": string } = { 5: 5, "foo": "foo" };
41
42var c: number;
43var d: string;
44var obj10: { [x: number]: number, [y: string]: number } = { [c]: 1, [d]: 2 };
45
46var obj11 = { get 5() { return 5; }, set "foo"(a: any) { } };
47obj9 = obj11;
48
49var obj12: { a?: number, b?: string, c?: boolean };
50obj12 = {};
51obj12 = { a: 5 };
52obj12 = { a: 5, b: "foo" };
53obj12 = { b: "foo" };
54obj12 = { b: "foo", a: 5 };
55obj12 = { a: 5, c: true };
56obj12 = { c: false, b: "bar" };
57
58interface interface1 {
59    a: number,
60    b: string,
61    c: number,
62}
63
64interface interface2 extends interface1 {
65    d: number
66}
67
68var obj13: interface2 = { a: 5, b: "foo", c: 5, d: 5 };
69var obj14: { a: number[] | [string, string, string], b?(a: number[]): string[] } | interface2;
70obj14 = obj13;
71obj14 = { a: 5, b: "foo", c: 5, d: 5 };
72obj14 = { a: [1, 2, 3] };
73obj14 = { a: ["foo", "bar", "baz"] };
74obj14 = { a: ["foo", "bar", "baz"], b: function (a: (number[])) { return ["foo", "bar", "baz"] } };
75
76interface interface3 {
77    a: number | string | boolean
78}
79
80interface interface4 extends interface3 {
81    a: number
82}
83
84interface interface5 extends interface3 {
85    a: string
86}
87
88interface interface6 extends interface3 {
89    a: boolean
90}
91
92var obj15: interface4 | interface5 | interface6;
93obj15 = { a: 5 };
94obj15 = { a: "foo" };
95obj15 = { a: true };
96