Skip to content
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
2 changes: 1 addition & 1 deletion internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -28999,7 +28999,7 @@ func (c *Checker) getContextualTypeForAssignmentExpression(binary *ast.BinaryExp
thisType := c.getTypeOfExpression(expr)
if ast.IsPropertyAccessExpression(left) {
name := left.Name()
if ast.IsPrivateIdentifier(name) {
if ast.IsPrivateIdentifier(name) && thisType.symbol != nil {
symbol = c.getPropertyOfType(thisType, binder.GetSymbolNameForPrivateIdentifier(thisType.symbol, name.Text()))
} else {
symbol = c.getPropertyOfType(thisType, name.Text())
Expand Down
38 changes: 38 additions & 0 deletions internal/fourslash/tests/privatePropertyOfUndefinedThis_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package fourslash_test

import (
"testing"

"github.com/microsoft/typescript-go/internal/fourslash"
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
"github.com/microsoft/typescript-go/internal/testutil"
)

func TestPrivatePropertyOfUndefinedThis(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `
this.#a = {};
export {};
`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.VerifyNonSuggestionDiagnostics(t, []*lsproto.Diagnostic{
{
Code: &lsproto.IntegerOrString{Integer: new(int32(2532))},
Message: "Object is possibly 'undefined'.",
Range: lsproto.Range{
Start: lsproto.Position{Line: 0, Character: 0},
End: lsproto.Position{Line: 0, Character: 4},
},
},
{
Code: &lsproto.IntegerOrString{Integer: new(int32(18016))},
Message: "Private identifiers are not allowed outside class bodies.",
Range: lsproto.Range{
Start: lsproto.Position{Line: 0, Character: 5},
End: lsproto.Position{Line: 0, Character: 7},
},
},
})
}
Loading