• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2* Copyright (c) Microsoft Corporation. All rights reserved.
3* Copyright (c) 2023 Huawei Device Co., Ltd.
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8*     http://www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*
16* This file has been modified by Huawei to verify type inference by adding verification statements.
17*/
18
19// === tests/cases/compiler/missingSelf.ts ===
20declare function AssertType(value:any, type:string):void;
21class CalcButton
22{
23    public a() { this.onClick();
24AssertType(this.onClick(), "void");
25
26AssertType(this.onClick, "() => void");
27
28AssertType(this, "this");
29}
30
31    public onClick() { }
32}
33
34class CalcButton2
35{
36    public b() { () => this.onClick();
37AssertType(() => this.onClick(), "() => void");
38
39AssertType(this.onClick(), "void");
40
41AssertType(this.onClick, "() => void");
42
43AssertType(this, "this");
44}
45
46    public onClick() { }
47}
48
49let c = new CalcButton();
50AssertType(c, "CalcButton");
51AssertType(new CalcButton(), "CalcButton");
52AssertType(CalcButton, "typeof CalcButton");
53
54c.a();
55AssertType(c.a(), "void");
56AssertType(c.a, "() => void");
57
58let c2 = new CalcButton2();
59AssertType(c2, "CalcButton2");
60AssertType(new CalcButton2(), "CalcButton2");
61AssertType(CalcButton2, "typeof CalcButton2");
62
63c2.b();
64AssertType(c2.b(), "void");
65AssertType(c2.b, "() => void");
66
67
68
69