Skip to content
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

Fixed inherited JSDoc lookup on static properties of classes with symbol-less base types #60873

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return getSymbolsOfParameterPropertyDeclaration(parameter, escapeLeadingUnderscores(parameterName));
},
getDeclaredTypeOfSymbol,
getBaseConstructorTypeOfClass,
getPropertiesOfType,
getPropertyOfType: (type, name) => getPropertyOfType(type, escapeLeadingUnderscores(name)),
getPrivateIdentifierPropertyOfType: (leftType: Type, name: string, location: Node) => {
Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5055,6 +5055,7 @@ export interface TypeChecker {
getTypeOfSymbolAtLocation(symbol: Symbol, node: Node): Type;
getTypeOfSymbol(symbol: Symbol): Type;
getDeclaredTypeOfSymbol(symbol: Symbol): Type;
/** @internal */ getBaseConstructorTypeOfClass(type: InterfaceType): Type;
getPropertiesOfType(type: Type): Symbol[];
getPropertyOfType(type: Type, propertyName: string): Symbol | undefined;
getPrivateIdentifierPropertyOfType(leftType: Type, name: string, location: Node): Symbol | undefined;
Expand Down
11 changes: 8 additions & 3 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1051,11 +1051,16 @@ function findBaseOfDeclaration<T>(checker: TypeChecker, declaration: Declaration
const classOrInterfaceDeclaration = declaration.parent?.kind === SyntaxKind.Constructor ? declaration.parent.parent : declaration.parent;
if (!classOrInterfaceDeclaration) return;

const isStaticMember = hasStaticModifier(declaration);
if (hasStaticModifier(declaration)) {
const classType = checker.getTypeAtLocation(classOrInterfaceDeclaration);
Debug.assert(classType.isClassOrInterface());
const staticBaseType = checker.getBaseConstructorTypeOfClass(classType);
const symbol = checker.getPropertyOfType(staticBaseType, declaration.symbol.name);
return symbol ? cb(symbol) : undefined;
}
return firstDefined(getAllSuperTypeNodes(classOrInterfaceDeclaration), superTypeNode => {
const baseType = checker.getTypeAtLocation(superTypeNode);
const type = isStaticMember && baseType.symbol ? checker.getTypeOfSymbol(baseType.symbol) : baseType;
const symbol = checker.getPropertyOfType(type, declaration.symbol.name);
const symbol = checker.getPropertyOfType(baseType, declaration.symbol.name);
return symbol ? cb(symbol) : undefined;
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
///<reference path="fourslash.ts" />

//// declare class BaseClass {
//// /** some documentation for instance method */
//// method(): string;
//// }
////
//// type AnyConstructor = abstract new (...args: any[]) => object;
////
//// function Mix<T extends AnyConstructor>(BaseClass: T) {
//// abstract class MixinClass extends BaseClass {
//// constructor(...args: any[]) {
//// super(...args);
//// }
//// }
////
//// return MixinClass;
//// }
////
//// declare class Mixed extends Mix(BaseClass) {
//// static method(): string;
//// }
////
//// Mixed.method/*1*/;

verify.quickInfoAt("1", "(method) Mixed.method(): string", undefined);
35 changes: 35 additions & 0 deletions tests/cases/fourslash/quickInfoJsDocOverridesWithMixin1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
///<reference path="fourslash.ts" />

//// declare class BaseClass {
//// /** some documentation for static method */
//// static staticMethod(): number;
////
//// /** some documentation for instance method */
//// instanceMethod(): string;
//// }
////
//// type AnyConstructor = abstract new (...args: any[]) => object;
////
//// function Mix<T extends AnyConstructor>(BaseClass: T) {
//// abstract class MixinClass extends BaseClass {
//// constructor(...args: any[]) {
//// super(...args);
//// }
//// }
////
//// return MixinClass;
//// }
////
//// declare class Mixed extends Mix(BaseClass) {
//// static staticMethod(): number;
////
//// instanceMethod(): string;
//// }
////
//// Mixed.staticMethod/*1*/;
////
//// const m = new Mixed();
//// m.instanceMethod/*2*/;

verify.quickInfoAt("1", "(method) Mixed.staticMethod(): number", "some documentation for static method");
verify.quickInfoAt("2", "(method) Mixed.instanceMethod(): string", "some documentation for instance method");
Loading