Skip to content

Commit 1dde7e0

Browse files
Copilotjakebailey
andauthored
Fix documentation inheritance for static method overrides on mixin intersection types (#3161)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
1 parent f29d39a commit 1dde7e0

File tree

3 files changed

+61
-6
lines changed

3 files changed

+61
-6
lines changed

internal/checker/exports.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,14 @@ func (c *Checker) GetBaseTypes(t *Type) []*Type {
243243
return c.getBaseTypes(t)
244244
}
245245

246+
func (c *Checker) GetApparentType(t *Type) *Type {
247+
return c.getApparentType(t)
248+
}
249+
250+
func (c *Checker) GetBaseConstructorTypeOfClass(t *Type) *Type {
251+
return c.getBaseConstructorTypeOfClass(t)
252+
}
253+
246254
func (c *Checker) GetRestTypeOfSignature(sig *Signature) *Type {
247255
return c.getRestTypeOfSignature(sig)
248256
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package fourslash_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/microsoft/typescript-go/internal/fourslash"
7+
"github.com/microsoft/typescript-go/internal/testutil"
8+
)
9+
10+
func TestHoverMixinOverrideDocumentation(t *testing.T) {
11+
t.Parallel()
12+
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
13+
14+
const content = `
15+
// @strict: true
16+
// @filename: main.ts
17+
18+
declare class BaseClass {
19+
/** some documentation */
20+
static method(): number;
21+
}
22+
23+
type AnyConstructor = abstract new (...args: any[]) => object
24+
25+
class MixinClass {}
26+
declare function Mix<T extends AnyConstructor>(BaseClass: T): typeof MixinClass & T;
27+
28+
declare class Mixed extends Mix(BaseClass) {
29+
static method(): number;
30+
}
31+
32+
Mixed./*1*/method;
33+
`
34+
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
35+
defer done()
36+
37+
f.VerifyQuickInfoAt(t, "1", "(method) Mixed.method(): number", "some documentation")
38+
}

internal/ls/hover.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -564,16 +564,25 @@ func getJSDocOrTag(c *checker.Checker, node *ast.Node) *ast.Node {
564564
}
565565
if ast.IsClassOrInterfaceLike(node.Parent) {
566566
isStatic := ast.HasStaticModifier(node)
567-
for _, baseType := range c.GetBaseTypes(c.GetDeclaredTypeOfSymbol(node.Parent.Symbol())) {
568-
t := baseType
569-
if isStatic && baseType.Symbol() != nil {
570-
t = c.GetTypeOfSymbol(baseType.Symbol())
571-
}
572-
if prop := c.GetPropertyOfType(t, symbol.Name); prop != nil && prop.ValueDeclaration != nil {
567+
classType := c.GetDeclaredTypeOfSymbol(node.Parent.Symbol())
568+
if isStatic {
569+
// For static members, use the checker's base constructor type resolution.
570+
// This correctly handles intersection constructor types from mixins
571+
// (e.g., typeof MixinClass & T) by preserving the full intersection.
572+
staticBaseType := c.GetApparentType(c.GetBaseConstructorTypeOfClass(classType))
573+
if prop := c.GetPropertyOfType(staticBaseType, symbol.Name); prop != nil && prop.ValueDeclaration != nil {
573574
if jsDoc := getJSDocOrTag(c, prop.ValueDeclaration); jsDoc != nil {
574575
return jsDoc
575576
}
576577
}
578+
} else {
579+
for _, baseType := range c.GetBaseTypes(classType) {
580+
if prop := c.GetPropertyOfType(baseType, symbol.Name); prop != nil && prop.ValueDeclaration != nil {
581+
if jsDoc := getJSDocOrTag(c, prop.ValueDeclaration); jsDoc != nil {
582+
return jsDoc
583+
}
584+
}
585+
}
577586
}
578587
}
579588
}

0 commit comments

Comments
 (0)