In services, show the aliasSymbol for a type even if it's not accessible in the current scope (#17433)
* In services, show the aliasSymbol for a type even if it's not accessible in the current scope * Rename flag
This commit is contained in:
parent
80a7ed9a42
commit
10c8d5effa
4 changed files with 21 additions and 3 deletions
|
@ -2156,6 +2156,11 @@ namespace ts {
|
|||
return false;
|
||||
}
|
||||
|
||||
function isTypeSymbolAccessible(typeSymbol: Symbol, enclosingDeclaration: Node): boolean {
|
||||
const access = isSymbolAccessible(typeSymbol, enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false);
|
||||
return access.accessibility === SymbolAccessibility.Accessible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given symbol in given enclosing declaration is accessible and mark all associated alias to be visible if requested
|
||||
*
|
||||
|
@ -2486,8 +2491,7 @@ namespace ts {
|
|||
// Ignore constraint/default when creating a usage (as opposed to declaration) of a type parameter.
|
||||
return createTypeReferenceNode(name, /*typeArguments*/ undefined);
|
||||
}
|
||||
if (!inTypeAlias && type.aliasSymbol &&
|
||||
isSymbolAccessible(type.aliasSymbol, context.enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false).accessibility === SymbolAccessibility.Accessible) {
|
||||
if (!inTypeAlias && type.aliasSymbol && isTypeSymbolAccessible(type.aliasSymbol, context.enclosingDeclaration)) {
|
||||
const name = symbolToTypeReferenceName(type.aliasSymbol);
|
||||
const typeArgumentNodes = mapToTypeNodes(type.aliasTypeArguments, context);
|
||||
return createTypeReferenceNode(name, typeArgumentNodes);
|
||||
|
@ -3254,7 +3258,7 @@ namespace ts {
|
|||
buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, nextFlags);
|
||||
}
|
||||
else if (!(flags & TypeFormatFlags.InTypeAlias) && type.aliasSymbol &&
|
||||
isSymbolAccessible(type.aliasSymbol, enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false).accessibility === SymbolAccessibility.Accessible) {
|
||||
((flags & TypeFormatFlags.UseAliasDefinedOutsideCurrentScope) || isTypeSymbolAccessible(type.aliasSymbol, enclosingDeclaration))) {
|
||||
const typeArguments = type.aliasTypeArguments;
|
||||
writeSymbolTypeReference(type.aliasSymbol, typeArguments, 0, length(typeArguments), nextFlags);
|
||||
}
|
||||
|
|
|
@ -2722,6 +2722,8 @@ namespace ts {
|
|||
AddUndefined = 1 << 13, // Add undefined to types of initialized, non-optional parameters
|
||||
WriteClassExpressionAsTypeLiteral = 1 << 14, // Write a type literal instead of (Anonymous class)
|
||||
InArrayType = 1 << 15, // Writing an array element type
|
||||
UseAliasDefinedOutsideCurrentScope = 1 << 16, // For a `type T = ... ` defined in a different file, write `T` instead of its value,
|
||||
// even though `T` can't be accessed in the current scope.
|
||||
}
|
||||
|
||||
export const enum SymbolFormatFlags {
|
||||
|
|
|
@ -1261,6 +1261,7 @@ namespace ts {
|
|||
}
|
||||
|
||||
export function signatureToDisplayParts(typechecker: TypeChecker, signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[] {
|
||||
flags |= TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
||||
return mapToDisplayParts(writer => {
|
||||
typechecker.getSymbolDisplayBuilder().buildSignatureDisplay(signature, writer, enclosingDeclaration, flags);
|
||||
});
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: /a.ts
|
||||
////export type X = { x: number };
|
||||
////export function f(x: X): void {}
|
||||
|
||||
// @Filename: /b.ts
|
||||
////import { f } from "./a";
|
||||
/////**/f({ x: 1 });
|
||||
|
||||
verify.quickInfoAt("", "(alias) f(x: X): void\nimport f");
|
Loading…
Reference in a new issue