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
2 changes: 1 addition & 1 deletion internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -13987,7 +13987,7 @@ func (c *Checker) checkAndReportErrorForResolvingImportAliasToTypeOnlySymbol(nod
// TODO: how to get name for export *?
name := "*"
if !ast.IsExportDeclaration(typeOnlyDeclaration) {
name = getNameFromImportDeclaration(typeOnlyDeclaration).Text()
name = typeOnlyDeclaration.Name().Text()
}
c.error(decl.ModuleReference, message).AddRelatedInfo(createDiagnosticForNode(typeOnlyDeclaration, relatedMessage, name))
}
Expand Down
14 changes: 0 additions & 14 deletions internal/checker/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,20 +189,6 @@ func IsInTypeQuery(node *ast.Node) bool {
}) != nil
}

func getNameFromImportDeclaration(node *ast.Node) *ast.Node {
switch node.Kind {
case ast.KindImportSpecifier:
return node.AsImportSpecifier().Name()
case ast.KindNamespaceImport:
return node.AsNamespaceImport().Name()
case ast.KindImportClause:
return node.AsImportClause().Name()
case ast.KindImportEqualsDeclaration:
return node.AsImportEqualsDeclaration().Name()
}
return nil
}

func nodeCanBeDecorated(useLegacyDecorators bool, node *ast.Node, parent *ast.Node, grandparent *ast.Node) bool {
// private names cannot be used with decorators yet
if useLegacyDecorators && node.Name() != nil && ast.IsPrivateIdentifier(node.Name()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
t.ts(2,14): error TS1379: An import alias cannot reference a declaration that was exported using 'export type'.


==== t.ts (1 errors) ====
import a = require("./a");
import foo = a.Foo
~~~~~
!!! error TS1379: An import alias cannot reference a declaration that was exported using 'export type'.
!!! related TS1377 a.ts:2:15: 'Foo' was exported here.

==== a.ts (0 errors) ====
type Foo = { x: number }
export type { Foo };

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

=== t.ts ===
import a = require("./a");
>a : Symbol(a, Decl(t.ts, 0, 0))

import foo = a.Foo
>foo : Symbol(foo, Decl(t.ts, 0, 26))
>a : Symbol(a, Decl(t.ts, 0, 0))
>Foo : Symbol(a.Foo, Decl(a.ts, 1, 13))

=== a.ts ===
type Foo = { x: number }
>Foo : Symbol(Foo, Decl(a.ts, 0, 0))
>x : Symbol(x, Decl(a.ts, 0, 12))

export type { Foo };
>Foo : Symbol(Foo, Decl(a.ts, 1, 13))

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

=== t.ts ===
import a = require("./a");
>a : typeof a

import foo = a.Foo
>foo : any
>a : typeof a
>Foo : foo

=== a.ts ===
type Foo = { x: number }
>Foo : Foo
>x : number

export type { Foo };
>Foo : Foo

11 changes: 11 additions & 0 deletions testdata/tests/cases/compiler/importAliasTypeOnlyExport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @target: esnext
// @module: commonjs
// @noEmit: true

// @filename: t.ts
import a = require("./a");
import foo = a.Foo

// @filename: a.ts
type Foo = { x: number }
export type { Foo };