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/types/typeRelationships/typeInference/keyofInferenceLowerPriorityThanReturn.ts === 20declare function AssertType(value:any, type:string):void; 21// #22736 22declare class Write { 23 protected dummy: Write; 24} 25 26declare class Col<s, a> { 27 protected dummy: [Col<s, a>, s, a]; 28} 29 30declare class Table<Req, Def> { 31 protected dummy: [Table<Req, Def>, Req, Def]; 32} 33 34type MakeTable<T1 extends object, T2 extends object> = { 35 [P in keyof T1]: Col<Write, T1[P]>; 36} & { 37 [P in keyof T2]: Col<Write, T2[P]>; 38 }; 39 40declare class ConflictTarget<Cols> { 41 public static tableColumns<Cols>(cols: (keyof Cols)[]): ConflictTarget<Cols>; 42 protected dummy: [ConflictTarget<Cols>, Cols]; 43} 44 45 46 47const bookTable: Table<BookReq, BookDef> = null as any 48AssertType(bookTable, "Table<BookReq, BookDef>"); 49AssertType(null as any, "any"); 50AssertType(null, "null"); 51 52interface BookReq { 53 readonly title: string; 54 readonly serial: number; 55} 56 57interface BookDef { 58 readonly author: string; 59 readonly numPages: number | null; 60} 61 62 63function insertOnConflictDoNothing<Req extends object, Def extends object>(_table: Table<Req, Def>, _conflictTarget: ConflictTarget<Req & Def>): boolean { 64 throw new Error(); 65AssertType(new Error(), "Error"); 66AssertType(Error, "ErrorConstructor"); 67} 68 69function f() { 70 insertOnConflictDoNothing(bookTable, ConflictTarget.tableColumns(["serial"])); // <-- No error here; should use the type inferred for the 71AssertType(insertOnConflictDoNothing(bookTable, ConflictTarget.tableColumns(["serial"])), "boolean"); 72AssertType(insertOnConflictDoNothing, "<Req extends object, Def extends object>(Table<Req, Def>, ConflictTarget<Req & Def>) => boolean"); 73AssertType(bookTable, "Table<BookReq, BookDef>"); 74AssertType(ConflictTarget.tableColumns(["serial"]), "ConflictTarget<BookReq & BookDef>"); 75AssertType(ConflictTarget.tableColumns, "<Cols>((keyof Cols)[]) => ConflictTarget<Cols>"); 76AssertType(["serial"], ""serial"[]"); 77AssertType("serial", "string"); 78return type of `tableColumns` 79} 80 81 82