1/* 2 * Copyright (c) 2023 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 17// infer to type argument 18type T5<T> = 19 T extends Promise<infer U extends string> ? ["string", U] : 20 T extends Promise<infer U extends number> ? ["number", U] : 21 never; 22 23type X5_T1 = T5<Promise<"a" | "b">>; // ["string", "a" | "b"] 24type X5_T2 = T5<Promise<1 | 2>>; // ["number", 1 | 2] 25type X5_T3 = T5<Promise<1n | 2n>>; // never 26 27// infer to property type 28type T6<T> = 29 T extends { a: infer U extends string } ? ["string", U] : 30 T extends { a: infer U extends number } ? ["number", U] : 31 never; 32 33type X6_T1 = T6<{ a: "a" }>; // ["string", "a"] 34type X6_T2 = T6<{ a: 1 }>; // ["number", 1] 35type X6_T3 = T6<{ a: object }>; // never 36 37// infer twice with same constraint 38type T7<T> = 39 T extends { a: infer U extends string, b: infer U extends string } ? ["string", U] : 40 T extends { a: infer U extends number, b: infer U extends number } ? ["number", U] : 41 never; 42