• 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/overrideBaseIntersectionMethod.ts ===
20declare function AssertType(value:any, type:string):void;
21// Repro from #14615
22
23type Constructor<T> = new (...args: any[]) => T;
24
25const WithLocation = <T extends Constructor<Point>>(Base: T) => class extends Base {
26AssertType(WithLocation, "<T extends Constructor<Point>>(T) => { new (...any[]): (Anonymous class); prototype: WithLocation<any>.(Anonymous class); } & T");
27AssertType(Base, "T");
28AssertType(class extends Base {  getLocation(): [number, number] {    const [x,y] = super.getLocation();    return [this.x | x, this.y | y];  }}, "{ new (...any[]): (Anonymous class); prototype: WithLocation<any>.(Anonymous class); } & T");
29AssertType(<T extends Constructor<Point>>(Base: T) => class extends Base {  getLocation(): [number, number] {    const [x,y] = super.getLocation();    return [this.x | x, this.y | y];  }}, "<T extends Constructor<Point>>(T) => { new (...any[]): (Anonymous class); prototype: WithLocation<any>.(Anonymous class); } & T");
30
31  getLocation(): [number, number] {
32AssertType(getLocation, "() => [number, number]");
33
34    const [x,y] = super.getLocation();
35AssertType(x, "number");
36AssertType(y, "number");
37AssertType(super.getLocation(), "[number, number]");
38AssertType(super.getLocation, "() => [number, number]");
39AssertType(super, "Point");
40
41AssertType([this.x | x, this.y | y], "[number, number]");
42AssertType(this.x | x, "number");
43AssertType(this.x, "number");
44AssertType(this, "this");
45AssertType(x, "number");
46AssertType(this.y | y, "number");
47AssertType(this.y, "number");
48AssertType(this, "this");
49AssertType(y, "number");
50    return [this.x | x, this.y | y];
51  }
52}
53
54class Point {
55  constructor(public x: number, public y: number) { }
56  getLocation(): [number, number] {
57AssertType([0,0], "[number, number]");
58AssertType(0, "int");
59AssertType(0, "int");
60    return [0,0];
61  }
62}
63
64class Foo extends WithLocation(Point) {
65  calculate() {
66AssertType(this.x + this.y, "number");
67AssertType(this.x, "number");
68AssertType(this, "this");
69AssertType(this.y, "number");
70AssertType(this, "this");
71    return this.x + this.y;
72  }
73  getLocation() {
74AssertType(super.getLocation(), "[number, number]");
75AssertType(super.getLocation, "(() => [number, number]) & (() => [number, number])");
76AssertType(super, "WithLocation<typeof Point>.(Anonymous class) & Point");
77    return super.getLocation()
78  }
79  whereAmI() {
80AssertType(this.getLocation(), "[number, number]");
81AssertType(this.getLocation, "() => [number, number]");
82AssertType(this, "this");
83    return this.getLocation();
84  }
85}
86
87
88