1/* 2 * Copyright (c) 2023-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 16function makeDate(timestamp: number): Date; 17function makeDate(m: number, d: number, y: number): Date; 18function makeDate(mOrTimestamp: number, d?: number, y?: number): Date { 19 if (d !== undefined && y !== undefined) { 20 return new Date(y, mOrTimestamp, d); 21 } else { 22 return new Date(mOrTimestamp); 23 } 24} 25const d1 = makeDate(12345678); 26const d2 = makeDate(5, 5, 5); 27 28function fn(x: string): string; 29function fn(x: number): string; 30function fn(x: string | number): string { 31 return 'foo'; 32} 33 34class C { 35 constructor(x: number, y: string); 36 constructor(s: string); 37 constructor(xs: any, y?: any) { 38 if (typeof xs === 'string') { 39 const lower = xs.toLowerCase(); 40 } 41 } 42 43 m(n: number): void; 44 m(s: string): void; 45 m(): void { 46 const n = 100 + 200; 47 } 48} 49let c = new C(10, 'foo'); 50c = new C('bar'); 51c.m(100); 52c.m('bazz'); 53 54abstract class AbstractClass { 55 abstract foo(n: number): void; 56 57 bar(s: string): void { 58 console.log(s); 59 } 60 61 abstract baz(s: string): void; // Overload 62 abstract baz(n: number): number; // Overload 63} 64 65declare class DeclareClass { 66 constructor(); 67 68 foo(): void; 69 70 bar(s: string): number; 71 72 baz(s: string): void; // Overload 73 baz(n: number): number; // Overload 74} 75 76declare function foobar(n: number): void; // Overload 77declare function foobar(s: string): string; // Overload 78 79declare function barbaz(b: boolean): void; 80 81namespace X { 82 function foo(x: number): void; // Overload 83 function foo(): void { 84 const n = 300 + 400; 85 } // Overload 86 87 export function bar(s: string): string; // Overload 88 export function bar(n: number): string; // Overload 89 export function bar(arg: number | string): string { 90 // Overload 91 return arg.toString(); 92 } 93} 94 95function f(): void { 96 function localFun(n: number): void; 97 function localFun(s: string): void; 98 function localFun(): void { 99 const n = 500 + 600; 100 } 101} 102interface I { 103 foo(x: number): void; // Overload 104 foo(s: string): number; // Overload 105} 106 107class StaticBlock { 108 static { 109 function foo(x: number): void; // Overload 110 function foo(s: string): void; // Overload 111 function foo(): void { 112 const n = 700 + 800; 113 } 114 } 115} 116