Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14262,6 +14262,9 @@ func (c *Checker) combineValueAndTypeSymbols(valueSymbol *ast.Symbol, typeSymbol
if valueSymbol == c.unknownSymbol && typeSymbol == c.unknownSymbol {
return c.unknownSymbol
}
if typeSymbol.Flags&ast.SymbolFlagsValue != 0 {
return typeSymbol
}
if valueSymbol.Flags&(ast.SymbolFlagsType|ast.SymbolFlagsNamespace) != 0 {
return valueSymbol
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
a.ts(7,16): error TS2702: 'Base' only refers to a type, but is being used as a namespace here.
a.ts(13,1): error TS2309: An export assignment cannot be used in a module with other exported elements.


==== a.ts (2 errors) ====
class Foo {}

export class Base<T> {
value!: T;
}

import _Base = Base;
~~~~
!!! error TS2702: 'Base' only refers to a type, but is being used as a namespace here.

namespace Foo {
export import Base = _Base;
}

export = Foo;
~~~~~~~~~~~~~
!!! error TS2309: An export assignment cannot be used in a module with other exported elements.

==== b.ts (0 errors) ====
import { Base } from "./a";

class Derived extends Base<string> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//// [tests/cases/compiler/exportAssignmentMerging10.ts] ////

=== a.ts ===
class Foo {}
>Foo : Symbol(Foo, Decl(a.ts, 0, 0), Decl(a.ts, 6, 20))

export class Base<T> {
>Base : Symbol(Base, Decl(a.ts, 0, 12))
>T : Symbol(T, Decl(a.ts, 2, 18))

value!: T;
>value : Symbol(Base.value, Decl(a.ts, 2, 22))
>T : Symbol(T, Decl(a.ts, 2, 18))
}

import _Base = Base;
>_Base : Symbol(_Base, Decl(a.ts, 4, 1))

namespace Foo {
>Foo : Symbol(Foo, Decl(a.ts, 0, 0), Decl(a.ts, 6, 20))

export import Base = _Base;
>Base : Symbol(Base, Decl(a.ts, 8, 15))
>_Base : Symbol(_Base, Decl(a.ts, 4, 1))
}

export = Foo;
>Foo : Symbol(Foo, Decl(a.ts, 0, 0), Decl(a.ts, 6, 20))

=== b.ts ===
import { Base } from "./a";
>Base : Symbol(Base, Decl(b.ts, 0, 8))

class Derived extends Base<string> {}
>Derived : Symbol(Derived, Decl(b.ts, 0, 27))
>Base : Symbol(Base, Decl(b.ts, 0, 8))

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//// [tests/cases/compiler/exportAssignmentMerging10.ts] ////

=== a.ts ===
class Foo {}
>Foo : Foo

export class Base<T> {
>Base : Base<T>

value!: T;
>value : T
}

import _Base = Base;
>_Base : any
>Base : any

namespace Foo {
>Foo : typeof Foo

export import Base = _Base;
>Base : any
>_Base : any
}

export = Foo;
>Foo : Foo

=== b.ts ===
import { Base } from "./a";
>Base : typeof Base

class Derived extends Base<string> {}
>Derived : Derived
>Base : Base<string>

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
a.d.ts(20,5): error TS2309: An export assignment cannot be used in a module with other exported elements.


==== a.d.ts (1 errors) ====
declare namespace A {
class Base<T> {
a: T;
}
}

declare namespace B {
class Base<T> {
b: T;
}
}

declare module "m" {
export class Base<T> {
top: T;
}

const value: typeof A | typeof B;

export = value;
~~~~~~~~~~~~~~~
!!! error TS2309: An export assignment cannot be used in a module with other exported elements.
}

==== b.ts (0 errors) ====
import { Base } from "m";

class Derived extends Base<string> {}

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//// [tests/cases/compiler/exportAssignmentMerging9.ts] ////

=== a.d.ts ===
declare namespace A {
>A : Symbol(A, Decl(a.d.ts, 0, 0))

class Base<T> {
>Base : Symbol(Base, Decl(a.d.ts, 0, 21))
>T : Symbol(T, Decl(a.d.ts, 1, 15))

a: T;
>a : Symbol(Base.a, Decl(a.d.ts, 1, 19))
>T : Symbol(T, Decl(a.d.ts, 1, 15))
}
}

declare namespace B {
>B : Symbol(B, Decl(a.d.ts, 4, 1))

class Base<T> {
>Base : Symbol(Base, Decl(a.d.ts, 6, 21))
>T : Symbol(T, Decl(a.d.ts, 7, 15))

b: T;
>b : Symbol(Base.b, Decl(a.d.ts, 7, 19))
>T : Symbol(T, Decl(a.d.ts, 7, 15))
}
}

declare module "m" {
>"m" : Symbol("m", Decl(a.d.ts, 10, 1))

export class Base<T> {
>Base : Symbol(Base, Decl(a.d.ts, 12, 20))
>T : Symbol(T, Decl(a.d.ts, 13, 22))

top: T;
>top : Symbol(Base.top, Decl(a.d.ts, 13, 26))
>T : Symbol(T, Decl(a.d.ts, 13, 22))
}

const value: typeof A | typeof B;
>value : Symbol(value, Decl(a.d.ts, 17, 9))
>A : Symbol(A, Decl(a.d.ts, 0, 0))
>B : Symbol(B, Decl(a.d.ts, 4, 1))

export = value;
>value : Symbol(value, Decl(a.d.ts, 17, 9))
}

=== b.ts ===
import { Base } from "m";
>Base : Symbol(Base, Decl(b.ts, 0, 8))

class Derived extends Base<string> {}
>Derived : Symbol(Derived, Decl(b.ts, 0, 25))
>Base : Symbol(Base, Decl(b.ts, 0, 8))

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//// [tests/cases/compiler/exportAssignmentMerging9.ts] ////

=== a.d.ts ===
declare namespace A {
>A : typeof A

class Base<T> {
>Base : Base<T>

a: T;
>a : T
}
}

declare namespace B {
>B : typeof B

class Base<T> {
>Base : Base<T>

b: T;
>b : T
}
}

declare module "m" {
>"m" : typeof import("m")

export class Base<T> {
>Base : Base<T>

top: T;
>top : T
}

const value: typeof A | typeof B;
>value : typeof A | typeof B
>A : typeof A
>B : typeof B

export = value;
>value : typeof A | typeof B
}

=== b.ts ===
import { Base } from "m";
>Base : typeof Base

class Derived extends Base<string> {}
>Derived : Derived
>Base : Base<string>

Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import { f } from 'demoModule';
// Assign an incorrect type here to see the type of 'f'.
let x1: string = demoNS.f;
>x1 : Symbol(x1, Decl(user.ts, 2, 3))
>demoNS.f : Symbol(demoNS.f, Decl(demo.d.ts, 0, 26))
>demoNS.f : Symbol(f, Decl(demo.d.ts, 0, 26))
>demoNS : Symbol(demoNS, Decl(demo.d.ts, 0, 0))
>f : Symbol(demoNS.f, Decl(demo.d.ts, 0, 26))
>f : Symbol(f, Decl(demo.d.ts, 0, 26))

let x2: string = f;
>x2 : Symbol(x2, Decl(user.ts, 3, 3))
Expand Down

This file was deleted.

Loading
Loading