• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
16declare function print(str:any):string;
17
18// one signature but no body
19class C {
20    constructor() {}
21
22    foo?(): string;
23
24    bar(): string {
25        return "test one signature but no body";
26    }
27}
28
29let c = new C();
30print(c.bar());
31
32// multi-signatures but one body
33class D {
34    constructor() {}
35
36    foo?(a: string): string;
37
38    foo?(a: string): string {
39        return a;
40    }
41
42    foo?(a: string, b?: string): string;
43
44    bar(): string {
45        return "test multi-signatures but one body";
46    }
47}
48
49let d = new D();
50print(d.foo!("D"));
51print(d.bar());
52
53// multi-signature but no body.
54class E {
55    constructor() {}
56
57    foo?(): string;
58
59    foo?(a: string): string;
60
61    foo?(a: string, b: string): string;
62
63    bar(): string {
64        return "test multi-signatures but no body";
65    }
66}
67
68E.prototype.foo = function(): string {
69    return "E";
70}
71
72let e = new E();
73print(e.foo!());
74print(e.bar());
75
76