1/* 2* Copyright (c) Microsoft Corporation. All rights reserved. 3* Copyright (c) 2023 Huawei Device Co., Ltd. 4* Licensed under the Apache License, Version 2.0 (the "License"); 5* you may not use this file except in compliance with the License. 6* You may obtain a copy of the License at 7* 8* http://www.apache.org/licenses/LICENSE-2.0 9* 10* Unless required by applicable law or agreed to in writing, software 11* distributed under the License is distributed on an "AS IS" BASIS, 12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13* See the License for the specific language governing permissions and 14* limitations under the License. 15* 16* This file has been modified by Huawei to verify type inference by adding verification statements. 17*/ 18 19// === tests/cases/conformance/expressions/arrayLiterals/arrayLiteralInference.ts === 20declare function AssertType(value:any, type:string):void; 21// Repro from #31204 22 23export enum AppType { 24 HeaderDetail = 'HeaderDetail', 25 HeaderMultiDetail = 'HeaderMultiDetail', 26 AdvancedList = 'AdvancedList', 27 Standard = 'Standard', 28 Relationship = 'Relationship', 29 Report = 'Report', 30 Composite = 'Composite', 31 ListOnly = 'ListOnly', 32 ModuleSettings = 'ModuleSettings' 33} 34 35export enum AppStyle { 36 Tree, 37 TreeEntity, 38 Standard, 39 MiniApp, 40 PivotTable 41} 42 43const appTypeStylesWithError: Map<AppType, Array<AppStyle>> = new Map([ 44AssertType(appTypeStylesWithError, "Map<AppType, AppStyle[]>"); 45AssertType(new Map([ [AppType.Standard, [AppStyle.Standard, AppStyle.MiniApp]], [AppType.Relationship, [AppStyle.Standard, AppStyle.Tree, AppStyle.TreeEntity]], [AppType.AdvancedList, [AppStyle.Standard, AppStyle.MiniApp]]]), "Map<union, union>"); 46AssertType(Map, "MapConstructor"); 47AssertType([ [AppType.Standard, [AppStyle.Standard, AppStyle.MiniApp]], [AppType.Relationship, [AppStyle.Standard, AppStyle.Tree, AppStyle.TreeEntity]], [AppType.AdvancedList, [AppStyle.Standard, AppStyle.MiniApp]]], "(union)[]"); 48 49 [AppType.Standard, [AppStyle.Standard, AppStyle.MiniApp]], 50AssertType([AppType.Standard, [AppStyle.Standard, AppStyle.MiniApp]], "[AppType.Standard, (union)[]]"); 51AssertType(AppType.Standard, "AppType.Standard"); 52AssertType([AppStyle.Standard, AppStyle.MiniApp], "(union)[]"); 53AssertType(AppStyle.Standard, "AppStyle.Standard"); 54AssertType(AppStyle.MiniApp, "AppStyle.MiniApp"); 55 56 [AppType.Relationship, [AppStyle.Standard, AppStyle.Tree, AppStyle.TreeEntity]], 57AssertType([AppType.Relationship, [AppStyle.Standard, AppStyle.Tree, AppStyle.TreeEntity]], "[AppType.Relationship, (union)[]]"); 58AssertType(AppType.Relationship, "AppType.Relationship"); 59AssertType([AppStyle.Standard, AppStyle.Tree, AppStyle.TreeEntity], "(union)[]"); 60AssertType(AppStyle.Standard, "AppStyle.Standard"); 61AssertType(AppStyle.Tree, "AppStyle.Tree"); 62AssertType(AppStyle.TreeEntity, "AppStyle.TreeEntity"); 63 64 [AppType.AdvancedList, [AppStyle.Standard, AppStyle.MiniApp]] 65AssertType([AppType.AdvancedList, [AppStyle.Standard, AppStyle.MiniApp]], "[AppType.AdvancedList, (union)[]]"); 66AssertType(AppType.AdvancedList, "AppType.AdvancedList"); 67AssertType([AppStyle.Standard, AppStyle.MiniApp], "(union)[]"); 68AssertType(AppStyle.Standard, "AppStyle.Standard"); 69AssertType(AppStyle.MiniApp, "AppStyle.MiniApp"); 70 71]); 72 73// Repro from #31204 74 75declare function foo<T>(...args: T[]): T[]; 76let b1: { x: boolean }[] = foo({ x: true }, { x: false }); 77AssertType(b1, "{ x: boolean; }[]"); 78AssertType(x, "boolean"); 79AssertType(foo({ x: true }, { x: false }), "(union)[]"); 80AssertType(foo, "<T>(...T[]) => T[]"); 81AssertType({ x: true }, "{ x: true; }"); 82AssertType(x, "boolean"); 83AssertType(true, "boolean"); 84AssertType({ x: false }, "{ x: false; }"); 85AssertType(x, "boolean"); 86AssertType(false, "boolean"); 87 88let b2: boolean[][] = foo([true], [false]); 89AssertType(b2, "boolean[][]"); 90AssertType(foo([true], [false]), "(union)[]"); 91AssertType(foo, "<T>(...T[]) => T[]"); 92AssertType([true], "true[]"); 93AssertType(true, "boolean"); 94AssertType([false], "false[]"); 95AssertType(false, "boolean"); 96 97 98