1/* 2 * Copyright (c) 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 16class A<T, U, K> { 17 public a: T; 18 public b: U; 19 public c: K; 20 21 constructor(a: T, b: U, c: K) { 22 this.a = a; 23 this.b = b; 24 this.c = c; 25 } 26} 27 28function foo<T, U extends Number, K, L extends A<T, K, T>>(a: A<T, K, int>, b: U, c: K, d: U, e: L) { 29 assert(typeof a.a == "int"); 30 assert(typeof a.b == "string"); 31 assert(typeof a.c == "number"); 32 assert(typeof b == "number"); 33 assert(typeof c == "string"); 34 assert(typeof d == "number"); 35 assert(typeof e == "object"); 36 return new A<T, U, K>(a.a, b, a.b); 37} 38 39function bar<T, U, K>(a: A<T, K, T>, b : U) { 40 assert(typeof a.a == "int"); 41 assert(typeof a.b == "string"); 42 assert(typeof a.c == "int"); 43 assert(typeof b == "number"); 44 return new A<T, U, K>(a.a, b, a.b); 45} 46 47function main() { 48 let a = new A<int, String, int>(10, "Test", 40); 49 let b: number = 20; 50 let c = foo(a, b, "Test", 20, a); 51 assert(typeof c.a == "number"); 52 assert(typeof c.b == "number"); 53 assert(typeof c.c == "string"); 54 let d = bar(a, b); 55 assert(typeof d.a == "number"); 56 assert(typeof d.b == "number"); 57 assert(typeof d.c == "string"); 58} 59