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
16import {
17    I,
18    foo,
19    I2,
20    I3,
21    bar,
22    C,
23    getDynamicObject,
24    dynamic_array,
25    padding,
26    margin,
27    position,
28    IndexedSignatureType,
29    postCardAction
30} from "./dynamic_lib"
31
32function main(): void {
33    let obj: I = {
34        f1: {a: 10, b: 20},
35        f2: [{c: 30}, {d: 40}],
36        "prop.xxx": 0
37    }
38
39    obj = {
40        f1: {e: "abc"},
41        f2: [{g: 50}]
42    }
43
44    obj.f1 = {f: 100}
45    obj.f1 = [{a1: 1}, {a2: 2, a3: 3}]
46
47    foo({f2: 'abc', f3: 30})
48    foo([{b1: 1, b2: 2}, {b3: '3'}])
49
50    let obj2: I2 = {
51        f1: {a: 10, b: 20},
52        f2: [{c: 30}, {d: 40}],
53        f3: {a: '11', b: 444, c: {f: {d: [1, 2]}}}
54    }
55    
56    bar({f2: 'abc', f3: 30})
57    bar([{b1: 1, b2: 2}, {b3: '3'}], {c: 4, d: 5})
58
59    let obj3: I3 = {
60        f1: {a: 10, b: 20},
61        f2: {a: '11', b: 444, c: {f: {d: [1, 2]}}},
62        f3: [{c: 30}, {d: 40}]
63    }
64}
65
66// #13412 - assign dynamic object (interop) to some static type from standard library
67interface InitProps {
68    p?: number;
69    q?: Record<string, Object> | undefined;
70    r?: Object | undefined | Record<string, Object>;
71}
72function createInitProps(c: C) {
73    let a: InitProps = {
74        p: c.a,
75        q: c.b
76    }
77
78    let b: InitProps = {
79        r: getDynamicObject()
80    }
81}
82
83// #13483 - pass object literal to method call of exported variable
84dynamic_array.splice(2, 0, {a: 1, b: '2'});
85
86// #13550 - allow literals as property names in dynamic context
87padding({'top': '0px', 'right': '5px', 'bottom': '10px', 'left': '15px'});
88margin({'top': '10px', 'right': '20px', 'bottom': '30px', 'left': '40px'});
89position({'x': '20', 'y': '40'});
90
91// allow literal as property name for type aliases that come from interop
92function typeAliasLitAsPropName(): IndexedSignatureType {
93    return {
94        'a': '1',
95        'b': '2',
96        'c': '3'
97    }
98}
99
100// #14399
101postCardAction({}, {
102    "action": 'router',
103    "abilityName": 'SomeAbility',
104    "params": {
105        "message": 'add detail'
106    }
107});