13af6ab5fSopenharmony_ci/* 23af6ab5fSopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 33af6ab5fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 43af6ab5fSopenharmony_ci * you may not use this file except in compliance with the License. 53af6ab5fSopenharmony_ci * You may obtain a copy of the License at 63af6ab5fSopenharmony_ci * 73af6ab5fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 83af6ab5fSopenharmony_ci * 93af6ab5fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 103af6ab5fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 113af6ab5fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 123af6ab5fSopenharmony_ci * See the License for the specific language governing permissions and 133af6ab5fSopenharmony_ci * limitations under the License. 143af6ab5fSopenharmony_ci */ 153af6ab5fSopenharmony_ci 163af6ab5fSopenharmony_cifunction makeDate(timestamp: number): Date; 173af6ab5fSopenharmony_cifunction makeDate(m: number, d: number, y: number): Date; 183af6ab5fSopenharmony_cifunction makeDate(mOrTimestamp: number, d?: number, y?: number): Date { 193af6ab5fSopenharmony_ci if (d !== undefined && y !== undefined) { 203af6ab5fSopenharmony_ci return new Date(y, mOrTimestamp, d); 213af6ab5fSopenharmony_ci } else { 223af6ab5fSopenharmony_ci return new Date(mOrTimestamp); 233af6ab5fSopenharmony_ci } 243af6ab5fSopenharmony_ci} 253af6ab5fSopenharmony_ciconst d1 = makeDate(12345678); 263af6ab5fSopenharmony_ciconst d2 = makeDate(5, 5, 5); 273af6ab5fSopenharmony_ci 283af6ab5fSopenharmony_cifunction fn(x: string): string; 293af6ab5fSopenharmony_cifunction fn(x: number): string; 303af6ab5fSopenharmony_cifunction fn(x: string | number): string { 313af6ab5fSopenharmony_ci return 'foo'; 323af6ab5fSopenharmony_ci} 333af6ab5fSopenharmony_ci 343af6ab5fSopenharmony_ciclass C { 353af6ab5fSopenharmony_ci constructor(x: number, y: string); 363af6ab5fSopenharmony_ci constructor(s: string); 373af6ab5fSopenharmony_ci constructor(xs: any, y?: any) { 383af6ab5fSopenharmony_ci if (typeof xs === 'string') { 393af6ab5fSopenharmony_ci const lower = xs.toLowerCase(); 403af6ab5fSopenharmony_ci } 413af6ab5fSopenharmony_ci } 423af6ab5fSopenharmony_ci 433af6ab5fSopenharmony_ci m(n: number): void; 443af6ab5fSopenharmony_ci m(s: string): void; 453af6ab5fSopenharmony_ci m(): void { 463af6ab5fSopenharmony_ci const n = 100 + 200; 473af6ab5fSopenharmony_ci } 483af6ab5fSopenharmony_ci} 493af6ab5fSopenharmony_cilet c = new C(10, 'foo'); 503af6ab5fSopenharmony_cic = new C('bar'); 513af6ab5fSopenharmony_cic.m(100); 523af6ab5fSopenharmony_cic.m('bazz'); 533af6ab5fSopenharmony_ci 543af6ab5fSopenharmony_ciabstract class AbstractClass { 553af6ab5fSopenharmony_ci abstract foo(n: number): void; 563af6ab5fSopenharmony_ci 573af6ab5fSopenharmony_ci bar(s: string): void { 583af6ab5fSopenharmony_ci console.log(s); 593af6ab5fSopenharmony_ci } 603af6ab5fSopenharmony_ci 613af6ab5fSopenharmony_ci abstract baz(s: string): void; // Overload 623af6ab5fSopenharmony_ci abstract baz(n: number): number; // Overload 633af6ab5fSopenharmony_ci} 643af6ab5fSopenharmony_ci 653af6ab5fSopenharmony_cideclare class DeclareClass { 663af6ab5fSopenharmony_ci constructor(); 673af6ab5fSopenharmony_ci 683af6ab5fSopenharmony_ci foo(): void; 693af6ab5fSopenharmony_ci 703af6ab5fSopenharmony_ci bar(s: string): number; 713af6ab5fSopenharmony_ci 723af6ab5fSopenharmony_ci baz(s: string): void; // Overload 733af6ab5fSopenharmony_ci baz(n: number): number; // Overload 743af6ab5fSopenharmony_ci} 753af6ab5fSopenharmony_ci 763af6ab5fSopenharmony_cideclare function foobar(n: number): void; // Overload 773af6ab5fSopenharmony_cideclare function foobar(s: string): string; // Overload 783af6ab5fSopenharmony_ci 793af6ab5fSopenharmony_cideclare function barbaz(b: boolean): void; 803af6ab5fSopenharmony_ci 813af6ab5fSopenharmony_cinamespace X { 823af6ab5fSopenharmony_ci function foo(x: number): void; // Overload 833af6ab5fSopenharmony_ci function foo(): void { 843af6ab5fSopenharmony_ci const n = 300 + 400; 853af6ab5fSopenharmony_ci } // Overload 863af6ab5fSopenharmony_ci 873af6ab5fSopenharmony_ci export function bar(s: string): string; // Overload 883af6ab5fSopenharmony_ci export function bar(n: number): string; // Overload 893af6ab5fSopenharmony_ci export function bar(arg: number | string): string { 903af6ab5fSopenharmony_ci // Overload 913af6ab5fSopenharmony_ci return arg.toString(); 923af6ab5fSopenharmony_ci } 933af6ab5fSopenharmony_ci} 943af6ab5fSopenharmony_ci 953af6ab5fSopenharmony_cifunction f(): void { 963af6ab5fSopenharmony_ci function localFun(n: number): void; 973af6ab5fSopenharmony_ci function localFun(s: string): void; 983af6ab5fSopenharmony_ci function localFun(): void { 993af6ab5fSopenharmony_ci const n = 500 + 600; 1003af6ab5fSopenharmony_ci } 1013af6ab5fSopenharmony_ci} 1023af6ab5fSopenharmony_ciinterface I { 1033af6ab5fSopenharmony_ci foo(x: number): void; // Overload 1043af6ab5fSopenharmony_ci foo(s: string): number; // Overload 1053af6ab5fSopenharmony_ci} 1063af6ab5fSopenharmony_ci 1073af6ab5fSopenharmony_ciclass StaticBlock { 1083af6ab5fSopenharmony_ci static { 1093af6ab5fSopenharmony_ci function foo(x: number): void; // Overload 1103af6ab5fSopenharmony_ci function foo(s: string): void; // Overload 1113af6ab5fSopenharmony_ci function foo(): void { 1123af6ab5fSopenharmony_ci const n = 700 + 800; 1133af6ab5fSopenharmony_ci } 1143af6ab5fSopenharmony_ci } 1153af6ab5fSopenharmony_ci} 116