-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Allow type-only namespace imports in implements clauses #36464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//// [tests/cases/conformance/externalModules/typeOnly/implementsClause.ts] //// | ||
|
||
//// [types.ts] | ||
export interface Component {} | ||
|
||
//// [ns.ts] | ||
import type * as types from './types'; | ||
export { types }; | ||
|
||
//// [index.ts] | ||
import type * as types from './types'; | ||
import * as nestedNamespace from './ns'; | ||
|
||
class C implements types.Component {} | ||
class D implements nestedNamespace.types.Component {} | ||
|
||
|
||
//// [types.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
//// [ns.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
//// [index.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
var C = /** @class */ (function () { | ||
function C() { | ||
} | ||
return C; | ||
}()); | ||
var D = /** @class */ (function () { | ||
function D() { | ||
} | ||
return D; | ||
}()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
=== tests/cases/conformance/externalModules/typeOnly/types.ts === | ||
export interface Component {} | ||
>Component : Symbol(Component, Decl(types.ts, 0, 0)) | ||
|
||
=== tests/cases/conformance/externalModules/typeOnly/ns.ts === | ||
import type * as types from './types'; | ||
>types : Symbol(types, Decl(ns.ts, 0, 11)) | ||
|
||
export { types }; | ||
>types : Symbol(types, Decl(ns.ts, 1, 8)) | ||
|
||
=== tests/cases/conformance/externalModules/typeOnly/index.ts === | ||
import type * as types from './types'; | ||
>types : Symbol(types, Decl(index.ts, 0, 11)) | ||
|
||
import * as nestedNamespace from './ns'; | ||
>nestedNamespace : Symbol(nestedNamespace, Decl(index.ts, 1, 6)) | ||
|
||
class C implements types.Component {} | ||
>C : Symbol(C, Decl(index.ts, 1, 40)) | ||
>types.Component : Symbol(types.Component, Decl(types.ts, 0, 0)) | ||
>types : Symbol(types, Decl(index.ts, 0, 11)) | ||
>Component : Symbol(types.Component, Decl(types.ts, 0, 0)) | ||
|
||
class D implements nestedNamespace.types.Component {} | ||
>D : Symbol(D, Decl(index.ts, 3, 37)) | ||
>nestedNamespace.types.Component : Symbol(types.Component, Decl(types.ts, 0, 0)) | ||
>nestedNamespace.types : Symbol(nestedNamespace.types, Decl(ns.ts, 1, 8)) | ||
>nestedNamespace : Symbol(nestedNamespace, Decl(index.ts, 1, 6)) | ||
>types : Symbol(nestedNamespace.types, Decl(ns.ts, 1, 8)) | ||
>Component : Symbol(types.Component, Decl(types.ts, 0, 0)) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
=== tests/cases/conformance/externalModules/typeOnly/types.ts === | ||
export interface Component {} | ||
No type information for this code. | ||
No type information for this code.=== tests/cases/conformance/externalModules/typeOnly/ns.ts === | ||
import type * as types from './types'; | ||
>types : typeof types | ||
|
||
export { types }; | ||
>types : typeof types | ||
|
||
=== tests/cases/conformance/externalModules/typeOnly/index.ts === | ||
import type * as types from './types'; | ||
>types : typeof types | ||
|
||
import * as nestedNamespace from './ns'; | ||
>nestedNamespace : typeof nestedNamespace | ||
|
||
class C implements types.Component {} | ||
>C : C | ||
>types : typeof types | ||
|
||
class D implements nestedNamespace.types.Component {} | ||
>D : D | ||
>nestedNamespace.types : any | ||
>nestedNamespace : typeof nestedNamespace | ||
>types : any | ||
|
13 changes: 13 additions & 0 deletions
13
tests/cases/conformance/externalModules/typeOnly/implementsClause.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// @Filename: types.ts | ||
export interface Component {} | ||
|
||
// @Filename: ns.ts | ||
import type * as types from './types'; | ||
export { types }; | ||
|
||
// @Filename: index.ts | ||
import type * as types from './types'; | ||
import * as nestedNamespace from './ns'; | ||
|
||
class C implements types.Component {} | ||
class D implements nestedNamespace.types.Component {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does it have to be the first identifier? Why can't it be anywhere?
(That long chain of
?.
s gives me the shivers.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this is a hot path and any other location in the node will be covered by other criteria of
isValidTypeOnlyAliasUseSite
, so it doesn’t make sense to check more than necessary.node
could be an identifier at the top level of a SourceFile, so I think that’d be SourceFile > ExpressionStatement > Identifier, so I guess only the last?.
is needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I don't think it checks the scenario of type ?
types.SomeInterfaceContainingNamespace.Component
since its parent is going to be one more level up than justtypes.Component
?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double checking that this is true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sheetalkamat this only gets called on identifiers from
resolveName
, which will only be the left-most identifier. The other parts of entity names get checked elsewhere.