You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix type-only imports in interface 'extends' and import=/export= (#36496)
* Handle when files get checked in different orders
* Fix interface extends clause
* Fix import= something type only from a module
* Revert apparently unnecessary addition
* Revert "Revert apparently unnecessary addition"
This reverts commit 7444b0b.
* Disallow `import = a.b.c` on anything with type-only imports
* Safety first
* Add test for TS Server single-file open
* Add big comment
* Extract error reporting function for import aliases
* Delete blank line
* Un-export, comment, and colocate some utils
* Combine 3 type-only marking function calls into one
* Add more export default tests
function getTargetOfAliasLikeExpression(expression: Expression, dontResolveAlias: boolean) {
@@ -2586,22 +2616,55 @@ namespace ts {
2586
2616
return links.target;
2587
2617
}
2588
2618
2589
-
function markSymbolOfAliasDeclarationIfResolvesToTypeOnly(aliasDeclaration: TypeOnlyCompatibleAliasDeclaration | undefined, resolvesToSymbol: Symbol | undefined) {
2590
-
if (!aliasDeclaration || !resolvesToSymbol) return;
2619
+
/**
2620
+
* Marks a symbol as type-only if its declaration is syntactically type-only.
2621
+
* If it is not itself marked type-only, but resolves to a type-only alias
2622
+
* somewhere in its resolution chain, save a reference to the type-only alias declaration
2623
+
* so the alias _not_ marked type-only can be identified as _transitively_ type-only.
2624
+
*
2625
+
* This function is called on each alias declaration that could be type-only or resolve to
2626
+
* another type-only alias during `resolveAlias`, so that later, when an alias is used in a
2627
+
* JS-emitting expression, we can quickly determine if that symbol is effectively type-only
2628
+
* and issue an error if so.
2629
+
*
2630
+
* @param aliasDeclaration The alias declaration not marked as type-only
2631
+
* has already been marked as not resolving to a type-only alias. Used when recursively resolving qualified
2632
+
* names of import aliases, e.g. `import C = a.b.C`. If namespace `a` is not found to be type-only, the
2633
+
* import declaration will initially be marked as not resolving to a type-only symbol. But, namespace `b`
2634
+
* must still be checked for a type-only marker, overwriting the previous negative result if found.
2635
+
* @param immediateTarget The symbol to which the alias declaration immediately resolves
2636
+
* @param finalTarget The symbol to which the alias declaration ultimately resolves
2637
+
* @param overwriteEmpty Checks `resolvesToSymbol` for type-only declarations even if `aliasDeclaration`
2638
+
*/
2639
+
function markSymbolOfAliasDeclarationIfTypeOnly(
2640
+
aliasDeclaration: Declaration | undefined,
2641
+
immediateTarget: Symbol | undefined,
2642
+
finalTarget: Symbol | undefined,
2643
+
overwriteEmpty: boolean,
2644
+
): boolean {
2645
+
if (!aliasDeclaration) return false;
2646
+
2647
+
// If the declaration itself is type-only, mark it and return.
0 commit comments