Skip to content

Commit 2f27e85

Browse files
committed
Test error w/exported class extending intersection
1 parent cd272e8 commit 2f27e85

6 files changed

+213
-59
lines changed

tests/baselines/reference/declarationEmitExpressionInExtends4.errors.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(2,10): error TS4060: Return type of exported function has or is using private name 'D'.
2+
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(6,7): error TS4093: Extends clause of exported class 'C' refers to a type with no declaration.
23
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(6,17): error TS2315: Type 'D' is not generic.
4+
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(10,7): error TS4093: Extends clause of exported class 'C2' refers to a type with no declaration.
35
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(10,18): error TS2304: Cannot find name 'SomeUndefinedFunction'.
46
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(15,18): error TS2304: Cannot find name 'SomeUndefinedFunction'.
57
tests/cases/compiler/declarationEmitExpressionInExtends4.ts(15,18): error TS4020: Extends clause of exported class 'C3' has or is using private name 'SomeUndefinedFunction'.
68

79

8-
==== tests/cases/compiler/declarationEmitExpressionInExtends4.ts (5 errors) ====
10+
==== tests/cases/compiler/declarationEmitExpressionInExtends4.ts (7 errors) ====
911

1012
function getSomething() {
1113
~~~~~~~~~~~~
@@ -14,12 +16,16 @@ tests/cases/compiler/declarationEmitExpressionInExtends4.ts(15,18): error TS4020
1416
}
1517

1618
class C extends getSomething()<number, string> {
19+
~
20+
!!! error TS4093: Extends clause of exported class 'C' refers to a type with no declaration.
1721
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1822
!!! error TS2315: Type 'D' is not generic.
1923

2024
}
2125

2226
class C2 extends SomeUndefinedFunction()<number, string> {
27+
~~
28+
!!! error TS4093: Extends clause of exported class 'C2' refers to a type with no declaration.
2329
~~~~~~~~~~~~~~~~~~~~~
2430
!!! error TS2304: Cannot find name 'SomeUndefinedFunction'.
2531

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
tests/cases/compiler/FinalClass.ts(4,14): error TS4093: Extends clause of exported class 'MyExtendedClass' refers to a type with no declaration.
2+
3+
4+
==== tests/cases/compiler/BaseClass.ts (0 errors) ====
5+
export type Constructor<T> = new (...args: any[]) => T;
6+
7+
export class MyBaseClass<T> {
8+
baseProperty: string;
9+
constructor(value: T) {}
10+
}
11+
==== tests/cases/compiler/MixinClass.ts (0 errors) ====
12+
import { Constructor, MyBaseClass } from './BaseClass';
13+
14+
export interface MyMixin {
15+
mixinProperty: string;
16+
}
17+
18+
export function MyMixin<T extends Constructor<MyBaseClass<any>>>(base: T): T & Constructor<MyMixin> {
19+
return class extends base {
20+
mixinProperty: string;
21+
}
22+
}
23+
==== tests/cases/compiler/FinalClass.ts (1 errors) ====
24+
import { MyBaseClass } from './BaseClass';
25+
import { MyMixin } from './MixinClass';
26+
27+
export class MyExtendedClass extends MyMixin(MyBaseClass)<string> {
28+
~~~~~~~~~~~~~~~
29+
!!! error TS4093: Extends clause of exported class 'MyExtendedClass' refers to a type with no declaration.
30+
extendedClassProperty: number;
31+
}
32+
==== tests/cases/compiler/Main.ts (0 errors) ====
33+
import { MyExtendedClass } from './FinalClass';
34+
import { MyMixin } from './MixinClass';
35+
36+
const myExtendedClass = new MyExtendedClass('string');
37+
38+
const AnotherMixedClass = MyMixin(MyExtendedClass);
39+
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
//// [tests/cases/compiler/exportClassExtendingIntersection.ts] ////
2+
3+
//// [BaseClass.ts]
4+
export type Constructor<T> = new (...args: any[]) => T;
5+
6+
export class MyBaseClass<T> {
7+
baseProperty: string;
8+
constructor(value: T) {}
9+
}
10+
//// [MixinClass.ts]
11+
import { Constructor, MyBaseClass } from './BaseClass';
12+
13+
export interface MyMixin {
14+
mixinProperty: string;
15+
}
16+
17+
export function MyMixin<T extends Constructor<MyBaseClass<any>>>(base: T): T & Constructor<MyMixin> {
18+
return class extends base {
19+
mixinProperty: string;
20+
}
21+
}
22+
//// [FinalClass.ts]
23+
import { MyBaseClass } from './BaseClass';
24+
import { MyMixin } from './MixinClass';
25+
26+
export class MyExtendedClass extends MyMixin(MyBaseClass)<string> {
27+
extendedClassProperty: number;
28+
}
29+
//// [Main.ts]
30+
import { MyExtendedClass } from './FinalClass';
31+
import { MyMixin } from './MixinClass';
32+
33+
const myExtendedClass = new MyExtendedClass('string');
34+
35+
const AnotherMixedClass = MyMixin(MyExtendedClass);
36+
37+
38+
//// [BaseClass.js]
39+
"use strict";
40+
exports.__esModule = true;
41+
var MyBaseClass = (function () {
42+
function MyBaseClass(value) {
43+
}
44+
return MyBaseClass;
45+
}());
46+
exports.MyBaseClass = MyBaseClass;
47+
//// [MixinClass.js]
48+
"use strict";
49+
var __extends = (this && this.__extends) || (function () {
50+
var extendStatics = Object.setPrototypeOf ||
51+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
52+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
53+
return function (d, b) {
54+
extendStatics(d, b);
55+
function __() { this.constructor = d; }
56+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
57+
};
58+
})();
59+
exports.__esModule = true;
60+
function MyMixin(base) {
61+
return (function (_super) {
62+
__extends(class_1, _super);
63+
function class_1() {
64+
return _super !== null && _super.apply(this, arguments) || this;
65+
}
66+
return class_1;
67+
}(base));
68+
}
69+
exports.MyMixin = MyMixin;
70+
//// [FinalClass.js]
71+
"use strict";
72+
var __extends = (this && this.__extends) || (function () {
73+
var extendStatics = Object.setPrototypeOf ||
74+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
75+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
76+
return function (d, b) {
77+
extendStatics(d, b);
78+
function __() { this.constructor = d; }
79+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
80+
};
81+
})();
82+
exports.__esModule = true;
83+
var BaseClass_1 = require("./BaseClass");
84+
var MixinClass_1 = require("./MixinClass");
85+
var MyExtendedClass = (function (_super) {
86+
__extends(MyExtendedClass, _super);
87+
function MyExtendedClass() {
88+
return _super !== null && _super.apply(this, arguments) || this;
89+
}
90+
return MyExtendedClass;
91+
}(MixinClass_1.MyMixin(BaseClass_1.MyBaseClass)));
92+
exports.MyExtendedClass = MyExtendedClass;
93+
//// [Main.js]
94+
"use strict";
95+
exports.__esModule = true;
96+
var FinalClass_1 = require("./FinalClass");
97+
var MixinClass_1 = require("./MixinClass");
98+
var myExtendedClass = new FinalClass_1.MyExtendedClass('string');
99+
var AnotherMixedClass = MixinClass_1.MyMixin(FinalClass_1.MyExtendedClass);
100+
101+
102+
//// [BaseClass.d.ts]
103+
export declare type Constructor<T> = new (...args: any[]) => T;
104+
export declare class MyBaseClass<T> {
105+
baseProperty: string;
106+
constructor(value: T);
107+
}
108+
//// [MixinClass.d.ts]
109+
import { Constructor, MyBaseClass } from './BaseClass';
110+
export interface MyMixin {
111+
mixinProperty: string;
112+
}
113+
export declare function MyMixin<T extends Constructor<MyBaseClass<any>>>(base: T): T & Constructor<MyMixin>;
114+
//// [Main.d.ts]

tests/baselines/reference/mixinAccessModifiers.errors.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,25 @@ tests/cases/conformance/classes/mixinAccessModifiers.ts(51,4): error TS2445: Pro
55
tests/cases/conformance/classes/mixinAccessModifiers.ts(66,7): error TS2415: Class 'C1' incorrectly extends base class 'Private & Private2'.
66
Type 'C1' is not assignable to type 'Private'.
77
Property 'p' has conflicting declarations and is inaccessible in type 'C1'.
8+
tests/cases/conformance/classes/mixinAccessModifiers.ts(66,7): error TS4093: Extends clause of exported class 'C1' refers to a type with no declaration.
89
tests/cases/conformance/classes/mixinAccessModifiers.ts(67,7): error TS2415: Class 'C2' incorrectly extends base class 'Private & Protected'.
910
Type 'C2' is not assignable to type 'Private'.
1011
Property 'p' has conflicting declarations and is inaccessible in type 'C2'.
12+
tests/cases/conformance/classes/mixinAccessModifiers.ts(67,7): error TS4093: Extends clause of exported class 'C2' refers to a type with no declaration.
1113
tests/cases/conformance/classes/mixinAccessModifiers.ts(68,7): error TS2415: Class 'C3' incorrectly extends base class 'Private & Public'.
1214
Type 'C3' is not assignable to type 'Private'.
1315
Property 'p' has conflicting declarations and is inaccessible in type 'C3'.
16+
tests/cases/conformance/classes/mixinAccessModifiers.ts(68,7): error TS4093: Extends clause of exported class 'C3' refers to a type with no declaration.
17+
tests/cases/conformance/classes/mixinAccessModifiers.ts(70,7): error TS4093: Extends clause of exported class 'C4' refers to a type with no declaration.
18+
tests/cases/conformance/classes/mixinAccessModifiers.ts(83,7): error TS4093: Extends clause of exported class 'C5' refers to a type with no declaration.
1419
tests/cases/conformance/classes/mixinAccessModifiers.ts(85,6): error TS2445: Property 'p' is protected and only accessible within class 'C4' and its subclasses.
1520
tests/cases/conformance/classes/mixinAccessModifiers.ts(90,6): error TS2445: Property 's' is protected and only accessible within class 'typeof C4' and its subclasses.
21+
tests/cases/conformance/classes/mixinAccessModifiers.ts(96,7): error TS4093: Extends clause of exported class 'C6' refers to a type with no declaration.
1622
tests/cases/conformance/classes/mixinAccessModifiers.ts(98,6): error TS2445: Property 'p' is protected and only accessible within class 'C4' and its subclasses.
1723
tests/cases/conformance/classes/mixinAccessModifiers.ts(103,6): error TS2445: Property 's' is protected and only accessible within class 'typeof C4' and its subclasses.
1824

1925

20-
==== tests/cases/conformance/classes/mixinAccessModifiers.ts (11 errors) ====
26+
==== tests/cases/conformance/classes/mixinAccessModifiers.ts (17 errors) ====
2127

2228
type Constructable = new (...args: any[]) => object;
2329

@@ -96,18 +102,26 @@ tests/cases/conformance/classes/mixinAccessModifiers.ts(103,6): error TS2445: Pr
96102
!!! error TS2415: Class 'C1' incorrectly extends base class 'Private & Private2'.
97103
!!! error TS2415: Type 'C1' is not assignable to type 'Private'.
98104
!!! error TS2415: Property 'p' has conflicting declarations and is inaccessible in type 'C1'.
105+
~~
106+
!!! error TS4093: Extends clause of exported class 'C1' refers to a type with no declaration.
99107
class C2 extends Mix(Private, Protected) {}
100108
~~
101109
!!! error TS2415: Class 'C2' incorrectly extends base class 'Private & Protected'.
102110
!!! error TS2415: Type 'C2' is not assignable to type 'Private'.
103111
!!! error TS2415: Property 'p' has conflicting declarations and is inaccessible in type 'C2'.
112+
~~
113+
!!! error TS4093: Extends clause of exported class 'C2' refers to a type with no declaration.
104114
class C3 extends Mix(Private, Public) {}
105115
~~
106116
!!! error TS2415: Class 'C3' incorrectly extends base class 'Private & Public'.
107117
!!! error TS2415: Type 'C3' is not assignable to type 'Private'.
108118
!!! error TS2415: Property 'p' has conflicting declarations and is inaccessible in type 'C3'.
119+
~~
120+
!!! error TS4093: Extends clause of exported class 'C3' refers to a type with no declaration.
109121

110122
class C4 extends Mix(Protected, Protected2) {
123+
~~
124+
!!! error TS4093: Extends clause of exported class 'C4' refers to a type with no declaration.
111125
f(c4: C4, c5: C5, c6: C6) {
112126
c4.p;
113127
c5.p;
@@ -121,6 +135,8 @@ tests/cases/conformance/classes/mixinAccessModifiers.ts(103,6): error TS2445: Pr
121135
}
122136

123137
class C5 extends Mix(Protected, Public) {
138+
~~
139+
!!! error TS4093: Extends clause of exported class 'C5' refers to a type with no declaration.
124140
f(c4: C4, c5: C5, c6: C6) {
125141
c4.p; // Error, not in class deriving from Protected2
126142
~
@@ -138,6 +154,8 @@ tests/cases/conformance/classes/mixinAccessModifiers.ts(103,6): error TS2445: Pr
138154
}
139155

140156
class C6 extends Mix(Public, Public2) {
157+
~~
158+
!!! error TS4093: Extends clause of exported class 'C6' refers to a type with no declaration.
141159
f(c4: C4, c5: C5, c6: C6) {
142160
c4.p; // Error, not in class deriving from Protected2
143161
~

tests/baselines/reference/mixinAccessModifiers.js

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -264,60 +264,3 @@ var C6 = (function (_super) {
264264
};
265265
return C6;
266266
}(Mix(Public, Public2)));
267-
268-
269-
//// [mixinAccessModifiers.d.ts]
270-
declare type Constructable = new (...args: any[]) => object;
271-
declare class Private {
272-
constructor(...args: any[]);
273-
private p;
274-
}
275-
declare class Private2 {
276-
constructor(...args: any[]);
277-
private p;
278-
}
279-
declare class Protected {
280-
constructor(...args: any[]);
281-
protected p: string;
282-
protected static s: string;
283-
}
284-
declare class Protected2 {
285-
constructor(...args: any[]);
286-
protected p: string;
287-
protected static s: string;
288-
}
289-
declare class Public {
290-
constructor(...args: any[]);
291-
p: string;
292-
static s: string;
293-
}
294-
declare class Public2 {
295-
constructor(...args: any[]);
296-
p: string;
297-
static s: string;
298-
}
299-
declare function f1(x: Private & Private2): void;
300-
declare function f2(x: Private & Protected): void;
301-
declare function f3(x: Private & Public): void;
302-
declare function f4(x: Protected & Protected2): void;
303-
declare function f5(x: Protected & Public): void;
304-
declare function f6(x: Public & Public2): void;
305-
declare function Mix<T, U>(c1: T, c2: U): T & U;
306-
declare class C1 extends Private & Private2 {
307-
}
308-
declare class C2 extends Private & Protected {
309-
}
310-
declare class C3 extends Private & Public {
311-
}
312-
declare class C4 extends Protected & Protected2 {
313-
f(c4: C4, c5: C5, c6: C6): void;
314-
static g(): void;
315-
}
316-
declare class C5 extends Protected & Public {
317-
f(c4: C4, c5: C5, c6: C6): void;
318-
static g(): void;
319-
}
320-
declare class C6 extends Public & Public2 {
321-
f(c4: C4, c5: C5, c6: C6): void;
322-
static g(): void;
323-
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// @declaration: true
2+
// @Filename:BaseClass.ts
3+
export type Constructor<T> = new (...args: any[]) => T;
4+
5+
export class MyBaseClass<T> {
6+
baseProperty: string;
7+
constructor(value: T) {}
8+
}
9+
// @Filename:MixinClass.ts
10+
import { Constructor, MyBaseClass } from './BaseClass';
11+
12+
export interface MyMixin {
13+
mixinProperty: string;
14+
}
15+
16+
export function MyMixin<T extends Constructor<MyBaseClass<any>>>(base: T): T & Constructor<MyMixin> {
17+
return class extends base {
18+
mixinProperty: string;
19+
}
20+
}
21+
// @Filename:FinalClass.ts
22+
import { MyBaseClass } from './BaseClass';
23+
import { MyMixin } from './MixinClass';
24+
25+
export class MyExtendedClass extends MyMixin(MyBaseClass)<string> {
26+
extendedClassProperty: number;
27+
}
28+
// @Filename:Main.ts
29+
import { MyExtendedClass } from './FinalClass';
30+
import { MyMixin } from './MixinClass';
31+
32+
const myExtendedClass = new MyExtendedClass('string');
33+
34+
const AnotherMixedClass = MyMixin(MyExtendedClass);

0 commit comments

Comments
 (0)