diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 96eb8295598..67a9a0da2f1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4665,6 +4665,9 @@ namespace ts { if (symbol && symbol.flags & SymbolFlags.TypeParameter && meaning & SymbolFlags.Type) { return { accessibility: SymbolAccessibility.Accessible }; } + if (!symbol && isThisIdentifier(firstIdentifier) && isSymbolAccessible(getSymbolOfNode(getThisContainer(firstIdentifier, /*includeArrowFunctions*/ false)), firstIdentifier, meaning, /*computeAliases*/ false).accessibility === SymbolAccessibility.Accessible) { + return { accessibility: SymbolAccessibility.Accessible }; + } // Verify if the symbol is accessible return (symbol && hasVisibleDeclarations(symbol, /*shouldComputeAliasToMakeVisible*/ true)) || { diff --git a/tests/baselines/reference/declarationEmitTypeofThisInClass.js b/tests/baselines/reference/declarationEmitTypeofThisInClass.js new file mode 100644 index 00000000000..03d7038c9fb --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeofThisInClass.js @@ -0,0 +1,20 @@ +//// [declarationEmitTypeofThisInClass.ts] +class Foo { + public foo!: string + public bar!: typeof this.foo //Public property 'bar' of exported class has or is using private name 'this'.(4031) +} + +//// [declarationEmitTypeofThisInClass.js] +"use strict"; +var Foo = /** @class */ (function () { + function Foo() { + } + return Foo; +}()); + + +//// [declarationEmitTypeofThisInClass.d.ts] +declare class Foo { + foo: string; + bar: typeof this.foo; +} diff --git a/tests/baselines/reference/declarationEmitTypeofThisInClass.symbols b/tests/baselines/reference/declarationEmitTypeofThisInClass.symbols new file mode 100644 index 00000000000..4c5b1ad92d1 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeofThisInClass.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/declarationEmitTypeofThisInClass.ts === +class Foo { +>Foo : Symbol(Foo, Decl(declarationEmitTypeofThisInClass.ts, 0, 0)) + + public foo!: string +>foo : Symbol(Foo.foo, Decl(declarationEmitTypeofThisInClass.ts, 0, 11)) + + public bar!: typeof this.foo //Public property 'bar' of exported class has or is using private name 'this'.(4031) +>bar : Symbol(Foo.bar, Decl(declarationEmitTypeofThisInClass.ts, 1, 23)) +>this.foo : Symbol(Foo.foo, Decl(declarationEmitTypeofThisInClass.ts, 0, 11)) +>this : Symbol(Foo, Decl(declarationEmitTypeofThisInClass.ts, 0, 0)) +>foo : Symbol(Foo.foo, Decl(declarationEmitTypeofThisInClass.ts, 0, 11)) +} diff --git a/tests/baselines/reference/declarationEmitTypeofThisInClass.types b/tests/baselines/reference/declarationEmitTypeofThisInClass.types new file mode 100644 index 00000000000..17f49b7b315 --- /dev/null +++ b/tests/baselines/reference/declarationEmitTypeofThisInClass.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/declarationEmitTypeofThisInClass.ts === +class Foo { +>Foo : Foo + + public foo!: string +>foo : string + + public bar!: typeof this.foo //Public property 'bar' of exported class has or is using private name 'this'.(4031) +>bar : string +>this.foo : string +>this : this +>foo : string +} diff --git a/tests/cases/compiler/declarationEmitTypeofThisInClass.ts b/tests/cases/compiler/declarationEmitTypeofThisInClass.ts new file mode 100644 index 00000000000..92c9c316244 --- /dev/null +++ b/tests/cases/compiler/declarationEmitTypeofThisInClass.ts @@ -0,0 +1,6 @@ +// @declaration: true +// @strict: true +class Foo { + public foo!: string + public bar!: typeof this.foo //Public property 'bar' of exported class has or is using private name 'this'.(4031) +} \ No newline at end of file