diff --git a/tests/baselines/reference/declarationEmitExpressionInExtends2.js b/tests/baselines/reference/declarationEmitExpressionInExtends2.js index 301d935a1db..ed3bc9d96f3 100644 --- a/tests/baselines/reference/declarationEmitExpressionInExtends2.js +++ b/tests/baselines/reference/declarationEmitExpressionInExtends2.js @@ -45,5 +45,6 @@ declare class C { y: U; } declare function getClass(c: T): typeof C; -declare class MyClass extends C { +declare var _MyClass_intersection_base: typeof C; +declare class MyClass extends _MyClass_intersection_base { } diff --git a/tests/baselines/reference/declarationEmitExpressionInExtends3.errors.txt b/tests/baselines/reference/declarationEmitExpressionInExtends3.errors.txt index 636085215ac..4864a3bcdc2 100644 --- a/tests/baselines/reference/declarationEmitExpressionInExtends3.errors.txt +++ b/tests/baselines/reference/declarationEmitExpressionInExtends3.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/declarationEmitExpressionInExtends3.ts(28,30): error TS4020: 'extends' clause of exported class 'MyClass' has or is using private name 'LocalClass'. -tests/cases/compiler/declarationEmitExpressionInExtends3.ts(36,31): error TS4020: 'extends' clause of exported class 'MyClass3' has or is using private name 'LocalInterface'. +tests/cases/compiler/declarationEmitExpressionInExtends3.ts(36,75): error TS4020: 'extends' clause of exported class 'MyClass3' has or is using private name 'LocalInterface'. ==== tests/cases/compiler/declarationEmitExpressionInExtends3.ts (2 errors) ==== @@ -41,7 +41,7 @@ tests/cases/compiler/declarationEmitExpressionInExtends3.ts(36,31): error TS4020 export class MyClass3 extends getExportedClass(undefined) { // Error LocalInterface is inaccisble - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ~~~~~~~~~~~~~~ !!! error TS4020: 'extends' clause of exported class 'MyClass3' has or is using private name 'LocalInterface'. } diff --git a/tests/baselines/reference/declarationEmitExpressionInExtends4.errors.txt b/tests/baselines/reference/declarationEmitExpressionInExtends4.errors.txt index b2e3eb58d54..54905212836 100644 --- a/tests/baselines/reference/declarationEmitExpressionInExtends4.errors.txt +++ b/tests/baselines/reference/declarationEmitExpressionInExtends4.errors.txt @@ -1,13 +1,12 @@ tests/cases/compiler/declarationEmitExpressionInExtends4.ts(1,10): error TS4060: Return type of exported function has or is using private name 'D'. -tests/cases/compiler/declarationEmitExpressionInExtends4.ts(5,7): error TS4093: 'extends' clause of exported class 'C' refers to a type whose name cannot be referenced. tests/cases/compiler/declarationEmitExpressionInExtends4.ts(5,17): error TS2315: Type 'D' is not generic. -tests/cases/compiler/declarationEmitExpressionInExtends4.ts(9,7): error TS4093: 'extends' clause of exported class 'C2' refers to a type whose name cannot be referenced. +tests/cases/compiler/declarationEmitExpressionInExtends4.ts(5,17): error TS4020: 'extends' clause of exported class 'C' has or is using private name 'D'. tests/cases/compiler/declarationEmitExpressionInExtends4.ts(9,18): error TS2304: Cannot find name 'SomeUndefinedFunction'. tests/cases/compiler/declarationEmitExpressionInExtends4.ts(14,18): error TS2304: Cannot find name 'SomeUndefinedFunction'. tests/cases/compiler/declarationEmitExpressionInExtends4.ts(14,18): error TS4020: 'extends' clause of exported class 'C3' has or is using private name 'SomeUndefinedFunction'. -==== tests/cases/compiler/declarationEmitExpressionInExtends4.ts (7 errors) ==== +==== tests/cases/compiler/declarationEmitExpressionInExtends4.ts (6 errors) ==== function getSomething() { ~~~~~~~~~~~~ !!! error TS4060: Return type of exported function has or is using private name 'D'. @@ -15,16 +14,14 @@ tests/cases/compiler/declarationEmitExpressionInExtends4.ts(14,18): error TS4020 } class C extends getSomething() { - ~ -!!! error TS4093: 'extends' clause of exported class 'C' refers to a type whose name cannot be referenced. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2315: Type 'D' is not generic. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS4020: 'extends' clause of exported class 'C' has or is using private name 'D'. } class C2 extends SomeUndefinedFunction() { - ~~ -!!! error TS4093: 'extends' clause of exported class 'C2' refers to a type whose name cannot be referenced. ~~~~~~~~~~~~~~~~~~~~~ !!! error TS2304: Cannot find name 'SomeUndefinedFunction'. diff --git a/tests/baselines/reference/exportClassExtendingIntersection.errors.txt b/tests/baselines/reference/exportClassExtendingIntersection.errors.txt deleted file mode 100644 index eb94869fdc2..00000000000 --- a/tests/baselines/reference/exportClassExtendingIntersection.errors.txt +++ /dev/null @@ -1,39 +0,0 @@ -tests/cases/compiler/FinalClass.ts(4,14): error TS4093: 'extends' clause of exported class 'MyExtendedClass' refers to a type whose name cannot be referenced. - - -==== tests/cases/compiler/BaseClass.ts (0 errors) ==== - export type Constructor = new (...args: any[]) => T; - - export class MyBaseClass { - baseProperty: string; - constructor(value: T) {} - } -==== tests/cases/compiler/MixinClass.ts (0 errors) ==== - import { Constructor, MyBaseClass } from './BaseClass'; - - export interface MyMixin { - mixinProperty: string; - } - - export function MyMixin>>(base: T): T & Constructor { - return class extends base { - mixinProperty: string; - } - } -==== tests/cases/compiler/FinalClass.ts (1 errors) ==== - import { MyBaseClass } from './BaseClass'; - import { MyMixin } from './MixinClass'; - - export class MyExtendedClass extends MyMixin(MyBaseClass) { - ~~~~~~~~~~~~~~~ -!!! error TS4093: 'extends' clause of exported class 'MyExtendedClass' refers to a type whose name cannot be referenced. - extendedClassProperty: number; - } -==== tests/cases/compiler/Main.ts (0 errors) ==== - import { MyExtendedClass } from './FinalClass'; - import { MyMixin } from './MixinClass'; - - const myExtendedClass = new MyExtendedClass('string'); - - const AnotherMixedClass = MyMixin(MyExtendedClass); - \ No newline at end of file diff --git a/tests/baselines/reference/exportClassExtendingIntersection.js b/tests/baselines/reference/exportClassExtendingIntersection.js index 2309a9af9b6..cfb3fd66842 100644 --- a/tests/baselines/reference/exportClassExtendingIntersection.js +++ b/tests/baselines/reference/exportClassExtendingIntersection.js @@ -111,4 +111,11 @@ export interface MyMixin { mixinProperty: string; } export declare function MyMixin>>(base: T): T & Constructor; +//// [FinalClass.d.ts] +import { MyBaseClass } from './BaseClass'; +import { MyMixin } from './MixinClass'; +declare var _MyExtendedClass_intersection_base: typeof MyBaseClass & (new (...args: any[]) => MyMixin); +export declare class MyExtendedClass extends _MyExtendedClass_intersection_base { + extendedClassProperty: number; +} //// [Main.d.ts] diff --git a/tests/baselines/reference/exportClassExtendingIntersection.symbols b/tests/baselines/reference/exportClassExtendingIntersection.symbols new file mode 100644 index 00000000000..b22febb7d72 --- /dev/null +++ b/tests/baselines/reference/exportClassExtendingIntersection.symbols @@ -0,0 +1,79 @@ +=== tests/cases/compiler/BaseClass.ts === +export type Constructor = new (...args: any[]) => T; +>Constructor : Symbol(Constructor, Decl(BaseClass.ts, 0, 0)) +>T : Symbol(T, Decl(BaseClass.ts, 0, 24)) +>args : Symbol(args, Decl(BaseClass.ts, 0, 34)) +>T : Symbol(T, Decl(BaseClass.ts, 0, 24)) + +export class MyBaseClass { +>MyBaseClass : Symbol(MyBaseClass, Decl(BaseClass.ts, 0, 55)) +>T : Symbol(T, Decl(BaseClass.ts, 2, 25)) + + baseProperty: string; +>baseProperty : Symbol(MyBaseClass.baseProperty, Decl(BaseClass.ts, 2, 29)) + + constructor(value: T) {} +>value : Symbol(value, Decl(BaseClass.ts, 4, 16)) +>T : Symbol(T, Decl(BaseClass.ts, 2, 25)) +} +=== tests/cases/compiler/MixinClass.ts === +import { Constructor, MyBaseClass } from './BaseClass'; +>Constructor : Symbol(Constructor, Decl(MixinClass.ts, 0, 8)) +>MyBaseClass : Symbol(MyBaseClass, Decl(MixinClass.ts, 0, 21)) + +export interface MyMixin { +>MyMixin : Symbol(MyMixin, Decl(MixinClass.ts, 0, 55), Decl(MixinClass.ts, 4, 1)) + + mixinProperty: string; +>mixinProperty : Symbol(MyMixin.mixinProperty, Decl(MixinClass.ts, 2, 26)) +} + +export function MyMixin>>(base: T): T & Constructor { +>MyMixin : Symbol(MyMixin, Decl(MixinClass.ts, 0, 55), Decl(MixinClass.ts, 4, 1)) +>T : Symbol(T, Decl(MixinClass.ts, 6, 24)) +>Constructor : Symbol(Constructor, Decl(MixinClass.ts, 0, 8)) +>MyBaseClass : Symbol(MyBaseClass, Decl(MixinClass.ts, 0, 21)) +>base : Symbol(base, Decl(MixinClass.ts, 6, 65)) +>T : Symbol(T, Decl(MixinClass.ts, 6, 24)) +>T : Symbol(T, Decl(MixinClass.ts, 6, 24)) +>Constructor : Symbol(Constructor, Decl(MixinClass.ts, 0, 8)) +>MyMixin : Symbol(MyMixin, Decl(MixinClass.ts, 0, 55), Decl(MixinClass.ts, 4, 1)) + + return class extends base { +>base : Symbol(base, Decl(MixinClass.ts, 6, 65)) + + mixinProperty: string; +>mixinProperty : Symbol((Anonymous class).mixinProperty, Decl(MixinClass.ts, 7, 31)) + } +} +=== tests/cases/compiler/FinalClass.ts === +import { MyBaseClass } from './BaseClass'; +>MyBaseClass : Symbol(MyBaseClass, Decl(FinalClass.ts, 0, 8)) + +import { MyMixin } from './MixinClass'; +>MyMixin : Symbol(MyMixin, Decl(FinalClass.ts, 1, 8)) + +export class MyExtendedClass extends MyMixin(MyBaseClass) { +>MyExtendedClass : Symbol(MyExtendedClass, Decl(FinalClass.ts, 1, 39)) +>MyMixin : Symbol(MyMixin, Decl(FinalClass.ts, 1, 8)) +>MyBaseClass : Symbol(MyBaseClass, Decl(FinalClass.ts, 0, 8)) + + extendedClassProperty: number; +>extendedClassProperty : Symbol(MyExtendedClass.extendedClassProperty, Decl(FinalClass.ts, 3, 67)) +} +=== tests/cases/compiler/Main.ts === +import { MyExtendedClass } from './FinalClass'; +>MyExtendedClass : Symbol(MyExtendedClass, Decl(Main.ts, 0, 8)) + +import { MyMixin } from './MixinClass'; +>MyMixin : Symbol(MyMixin, Decl(Main.ts, 1, 8)) + +const myExtendedClass = new MyExtendedClass('string'); +>myExtendedClass : Symbol(myExtendedClass, Decl(Main.ts, 3, 5)) +>MyExtendedClass : Symbol(MyExtendedClass, Decl(Main.ts, 0, 8)) + +const AnotherMixedClass = MyMixin(MyExtendedClass); +>AnotherMixedClass : Symbol(AnotherMixedClass, Decl(Main.ts, 5, 5)) +>MyMixin : Symbol(MyMixin, Decl(Main.ts, 1, 8)) +>MyExtendedClass : Symbol(MyExtendedClass, Decl(Main.ts, 0, 8)) + diff --git a/tests/baselines/reference/exportClassExtendingIntersection.types b/tests/baselines/reference/exportClassExtendingIntersection.types new file mode 100644 index 00000000000..5840c53a056 --- /dev/null +++ b/tests/baselines/reference/exportClassExtendingIntersection.types @@ -0,0 +1,84 @@ +=== tests/cases/compiler/BaseClass.ts === +export type Constructor = new (...args: any[]) => T; +>Constructor : Constructor +>T : T +>args : any[] +>T : T + +export class MyBaseClass { +>MyBaseClass : MyBaseClass +>T : T + + baseProperty: string; +>baseProperty : string + + constructor(value: T) {} +>value : T +>T : T +} +=== tests/cases/compiler/MixinClass.ts === +import { Constructor, MyBaseClass } from './BaseClass'; +>Constructor : any +>MyBaseClass : typeof MyBaseClass + +export interface MyMixin { +>MyMixin : MyMixin + + mixinProperty: string; +>mixinProperty : string +} + +export function MyMixin>>(base: T): T & Constructor { +>MyMixin : >>(base: T) => T & Constructor +>T : T +>Constructor : Constructor +>MyBaseClass : MyBaseClass +>base : T +>T : T +>T : T +>Constructor : Constructor +>MyMixin : MyMixin + + return class extends base { +>class extends base { mixinProperty: string; } : { new (...args: any[]): (Anonymous class); prototype: MyMixin.(Anonymous class); } & T +>base : MyBaseClass + + mixinProperty: string; +>mixinProperty : string + } +} +=== tests/cases/compiler/FinalClass.ts === +import { MyBaseClass } from './BaseClass'; +>MyBaseClass : typeof MyBaseClass + +import { MyMixin } from './MixinClass'; +>MyMixin : MyBaseClass>(base: T) => T & (new (...args: any[]) => MyMixin) + +export class MyExtendedClass extends MyMixin(MyBaseClass) { +>MyExtendedClass : MyExtendedClass +>MyMixin(MyBaseClass) : MyBaseClass & MyMixin +>MyMixin : MyBaseClass>(base: T) => T & (new (...args: any[]) => MyMixin) +>MyBaseClass : typeof MyBaseClass + + extendedClassProperty: number; +>extendedClassProperty : number +} +=== tests/cases/compiler/Main.ts === +import { MyExtendedClass } from './FinalClass'; +>MyExtendedClass : typeof MyExtendedClass + +import { MyMixin } from './MixinClass'; +>MyMixin : MyBaseClass>(base: T) => T & (new (...args: any[]) => MyMixin) + +const myExtendedClass = new MyExtendedClass('string'); +>myExtendedClass : MyExtendedClass +>new MyExtendedClass('string') : MyExtendedClass +>MyExtendedClass : typeof MyExtendedClass +>'string' : "string" + +const AnotherMixedClass = MyMixin(MyExtendedClass); +>AnotherMixedClass : typeof MyExtendedClass & (new (...args: any[]) => MyMixin) +>MyMixin(MyExtendedClass) : typeof MyExtendedClass & (new (...args: any[]) => MyMixin) +>MyMixin : MyBaseClass>(base: T) => T & (new (...args: any[]) => MyMixin) +>MyExtendedClass : typeof MyExtendedClass + diff --git a/tests/baselines/reference/mixinAccessModifiers.errors.txt b/tests/baselines/reference/mixinAccessModifiers.errors.txt index a93725e01d2..fa2fc4ac99a 100644 --- a/tests/baselines/reference/mixinAccessModifiers.errors.txt +++ b/tests/baselines/reference/mixinAccessModifiers.errors.txt @@ -5,25 +5,19 @@ tests/cases/conformance/classes/mixinAccessModifiers.ts(50,4): error TS2445: Pro tests/cases/conformance/classes/mixinAccessModifiers.ts(65,7): error TS2415: Class 'C1' incorrectly extends base class 'Private & Private2'. Type 'C1' is not assignable to type 'Private'. Property 'p' has conflicting declarations and is inaccessible in type 'C1'. -tests/cases/conformance/classes/mixinAccessModifiers.ts(65,7): error TS4093: 'extends' clause of exported class 'C1' refers to a type whose name cannot be referenced. tests/cases/conformance/classes/mixinAccessModifiers.ts(66,7): error TS2415: Class 'C2' incorrectly extends base class 'Private & Protected'. Type 'C2' is not assignable to type 'Private'. Property 'p' has conflicting declarations and is inaccessible in type 'C2'. -tests/cases/conformance/classes/mixinAccessModifiers.ts(66,7): error TS4093: 'extends' clause of exported class 'C2' refers to a type whose name cannot be referenced. tests/cases/conformance/classes/mixinAccessModifiers.ts(67,7): error TS2415: Class 'C3' incorrectly extends base class 'Private & Public'. Type 'C3' is not assignable to type 'Private'. Property 'p' has conflicting declarations and is inaccessible in type 'C3'. -tests/cases/conformance/classes/mixinAccessModifiers.ts(67,7): error TS4093: 'extends' clause of exported class 'C3' refers to a type whose name cannot be referenced. -tests/cases/conformance/classes/mixinAccessModifiers.ts(69,7): error TS4093: 'extends' clause of exported class 'C4' refers to a type whose name cannot be referenced. -tests/cases/conformance/classes/mixinAccessModifiers.ts(82,7): error TS4093: 'extends' clause of exported class 'C5' refers to a type whose name cannot be referenced. tests/cases/conformance/classes/mixinAccessModifiers.ts(84,6): error TS2445: Property 'p' is protected and only accessible within class 'C4' and its subclasses. tests/cases/conformance/classes/mixinAccessModifiers.ts(89,6): error TS2445: Property 's' is protected and only accessible within class 'typeof C4' and its subclasses. -tests/cases/conformance/classes/mixinAccessModifiers.ts(95,7): error TS4093: 'extends' clause of exported class 'C6' refers to a type whose name cannot be referenced. tests/cases/conformance/classes/mixinAccessModifiers.ts(97,6): error TS2445: Property 'p' is protected and only accessible within class 'C4' and its subclasses. tests/cases/conformance/classes/mixinAccessModifiers.ts(102,6): error TS2445: Property 's' is protected and only accessible within class 'typeof C4' and its subclasses. -==== tests/cases/conformance/classes/mixinAccessModifiers.ts (17 errors) ==== +==== tests/cases/conformance/classes/mixinAccessModifiers.ts (11 errors) ==== type Constructable = new (...args: any[]) => object; class Private { @@ -101,26 +95,18 @@ tests/cases/conformance/classes/mixinAccessModifiers.ts(102,6): error TS2445: Pr !!! error TS2415: Class 'C1' incorrectly extends base class 'Private & Private2'. !!! error TS2415: Type 'C1' is not assignable to type 'Private'. !!! error TS2415: Property 'p' has conflicting declarations and is inaccessible in type 'C1'. - ~~ -!!! error TS4093: 'extends' clause of exported class 'C1' refers to a type whose name cannot be referenced. class C2 extends Mix(Private, Protected) {} ~~ !!! error TS2415: Class 'C2' incorrectly extends base class 'Private & Protected'. !!! error TS2415: Type 'C2' is not assignable to type 'Private'. !!! error TS2415: Property 'p' has conflicting declarations and is inaccessible in type 'C2'. - ~~ -!!! error TS4093: 'extends' clause of exported class 'C2' refers to a type whose name cannot be referenced. class C3 extends Mix(Private, Public) {} ~~ !!! error TS2415: Class 'C3' incorrectly extends base class 'Private & Public'. !!! error TS2415: Type 'C3' is not assignable to type 'Private'. !!! error TS2415: Property 'p' has conflicting declarations and is inaccessible in type 'C3'. - ~~ -!!! error TS4093: 'extends' clause of exported class 'C3' refers to a type whose name cannot be referenced. class C4 extends Mix(Protected, Protected2) { - ~~ -!!! error TS4093: 'extends' clause of exported class 'C4' refers to a type whose name cannot be referenced. f(c4: C4, c5: C5, c6: C6) { c4.p; c5.p; @@ -134,8 +120,6 @@ tests/cases/conformance/classes/mixinAccessModifiers.ts(102,6): error TS2445: Pr } class C5 extends Mix(Protected, Public) { - ~~ -!!! error TS4093: 'extends' clause of exported class 'C5' refers to a type whose name cannot be referenced. f(c4: C4, c5: C5, c6: C6) { c4.p; // Error, not in class deriving from Protected2 ~ @@ -153,8 +137,6 @@ tests/cases/conformance/classes/mixinAccessModifiers.ts(102,6): error TS2445: Pr } class C6 extends Mix(Public, Public2) { - ~~ -!!! error TS4093: 'extends' clause of exported class 'C6' refers to a type whose name cannot be referenced. f(c4: C4, c5: C5, c6: C6) { c4.p; // Error, not in class deriving from Protected2 ~ diff --git a/tests/baselines/reference/mixinAccessModifiers.js b/tests/baselines/reference/mixinAccessModifiers.js index 8100c9db9e9..9abb2d00722 100644 --- a/tests/baselines/reference/mixinAccessModifiers.js +++ b/tests/baselines/reference/mixinAccessModifiers.js @@ -263,3 +263,66 @@ var C6 = (function (_super) { }; return C6; }(Mix(Public, Public2))); + + +//// [mixinAccessModifiers.d.ts] +declare type Constructable = new (...args: any[]) => object; +declare class Private { + constructor(...args: any[]); + private p; +} +declare class Private2 { + constructor(...args: any[]); + private p; +} +declare class Protected { + constructor(...args: any[]); + protected p: string; + protected static s: string; +} +declare class Protected2 { + constructor(...args: any[]); + protected p: string; + protected static s: string; +} +declare class Public { + constructor(...args: any[]); + p: string; + static s: string; +} +declare class Public2 { + constructor(...args: any[]); + p: string; + static s: string; +} +declare function f1(x: Private & Private2): void; +declare function f2(x: Private & Protected): void; +declare function f3(x: Private & Public): void; +declare function f4(x: Protected & Protected2): void; +declare function f5(x: Protected & Public): void; +declare function f6(x: Public & Public2): void; +declare function Mix(c1: T, c2: U): T & U; +declare var _C1_intersection_base: typeof Private & typeof Private2; +declare class C1 extends _C1_intersection_base { +} +declare var _C2_intersection_base: typeof Private & typeof Protected; +declare class C2 extends _C2_intersection_base { +} +declare var _C3_intersection_base: typeof Private & typeof Public; +declare class C3 extends _C3_intersection_base { +} +declare var _C4_intersection_base: typeof Protected & typeof Protected2; +declare class C4 extends _C4_intersection_base { + f(c4: C4, c5: C5, c6: C6): void; + static g(): void; +} +declare var _C5_intersection_base: typeof Protected & typeof Public; +declare class C5 extends _C5_intersection_base { + f(c4: C4, c5: C5, c6: C6): void; + static g(): void; +} +declare var _C6_intersection_base: typeof Public & typeof Public2; +declare class C6 extends _C6_intersection_base { + f(c4: C4, c5: C5, c6: C6): void; + static g(): void; +}