1/* 2 * Copyright (c) 2022-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 16import { User, Person, Fruit, Apple, foo, bar, X, Y } from "./oh_modules/object_literal_constructor" 17 18//Variable Declaration 19let user: User = { id: 1 } 20 21let fruit: Fruit = new Fruit("fruit"); // legal 22 23let person: Person = { name: "Furkan", age: "25" } 24 25const base = { title: 'value' }; 26const y: X = { ...base }; 27 28// Call expression 29foo({name:" cfe"}); 30foo(new X("cfe")); //legal 31bar({name:" cfe"}); //legal 32 33//Return statement 34function createItem(): X { 35 return { title: 'item' }; 36} 37 38function getClass(): X { 39 return new X("cfe"); //legal 40} 41 42function createItem2(): Y { 43 return { title: 'item' }; //legal 44} 45 46// Property Declaration 47class Wrapper { 48 item: X = { title: 'invalid' }; 49} 50 51class WrapperLegal { 52 item: X = new X("cfe"); //legal 53} 54 55// As Expression 56const x = { title: 'value' } as X; 57const val = new X("cfe") as X; //legal 58 59// Conditional Expression 60const condition = true; 61 62const value: X = condition ? { title: 'hello' } : new X("cfe"); 63 64const value2: X = condition ? new Fruit("ase") : new X("sea"); //legal 65 66//Binary Expression 67let u: X; 68 69u = { 70 a: 'assign', 71 b: 88 72}; 73 74u = new Fruit("apple") // legal 75 76//ArrayLiteralExpression 77const arr: X[] = [ 78 { a: 'fail', b: 5 }, 79 { a: 'bad', b: 6 } 80 ]; 81 82const arrLegal: X[] = [new X("cfe"), new X("cfe")]; //legal