Skip to content

Commit eb4b8a4

Browse files
authored
Handle this in isEntityNameVisible (microsoft#49521)
1 parent 89d05f7 commit eb4b8a4

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4665,6 +4665,9 @@ namespace ts {
46654665
if (symbol && symbol.flags & SymbolFlags.TypeParameter && meaning & SymbolFlags.Type) {
46664666
return { accessibility: SymbolAccessibility.Accessible };
46674667
}
4668+
if (!symbol && isThisIdentifier(firstIdentifier) && isSymbolAccessible(getSymbolOfNode(getThisContainer(firstIdentifier, /*includeArrowFunctions*/ false)), firstIdentifier, meaning, /*computeAliases*/ false).accessibility === SymbolAccessibility.Accessible) {
4669+
return { accessibility: SymbolAccessibility.Accessible };
4670+
}
46684671

46694672
// Verify if the symbol is accessible
46704673
return (symbol && hasVisibleDeclarations(symbol, /*shouldComputeAliasToMakeVisible*/ true)) || {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [declarationEmitTypeofThisInClass.ts]
2+
class Foo {
3+
public foo!: string
4+
public bar!: typeof this.foo //Public property 'bar' of exported class has or is using private name 'this'.(4031)
5+
}
6+
7+
//// [declarationEmitTypeofThisInClass.js]
8+
"use strict";
9+
var Foo = /** @class */ (function () {
10+
function Foo() {
11+
}
12+
return Foo;
13+
}());
14+
15+
16+
//// [declarationEmitTypeofThisInClass.d.ts]
17+
declare class Foo {
18+
foo: string;
19+
bar: typeof this.foo;
20+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/declarationEmitTypeofThisInClass.ts ===
2+
class Foo {
3+
>Foo : Symbol(Foo, Decl(declarationEmitTypeofThisInClass.ts, 0, 0))
4+
5+
public foo!: string
6+
>foo : Symbol(Foo.foo, Decl(declarationEmitTypeofThisInClass.ts, 0, 11))
7+
8+
public bar!: typeof this.foo //Public property 'bar' of exported class has or is using private name 'this'.(4031)
9+
>bar : Symbol(Foo.bar, Decl(declarationEmitTypeofThisInClass.ts, 1, 23))
10+
>this.foo : Symbol(Foo.foo, Decl(declarationEmitTypeofThisInClass.ts, 0, 11))
11+
>this : Symbol(Foo, Decl(declarationEmitTypeofThisInClass.ts, 0, 0))
12+
>foo : Symbol(Foo.foo, Decl(declarationEmitTypeofThisInClass.ts, 0, 11))
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/declarationEmitTypeofThisInClass.ts ===
2+
class Foo {
3+
>Foo : Foo
4+
5+
public foo!: string
6+
>foo : string
7+
8+
public bar!: typeof this.foo //Public property 'bar' of exported class has or is using private name 'this'.(4031)
9+
>bar : string
10+
>this.foo : string
11+
>this : this
12+
>foo : string
13+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @declaration: true
2+
// @strict: true
3+
class Foo {
4+
public foo!: string
5+
public bar!: typeof this.foo //Public property 'bar' of exported class has or is using private name 'this'.(4031)
6+
}

0 commit comments

Comments
 (0)