diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 32965372e83fc..2bb8eee42fb8f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7628,7 +7628,7 @@ namespace ts { return addOptionality(type, isOptional); } - if (isPropertyDeclaration(declaration) && (noImplicitAny || isInJSFile(declaration))) { + if (isPropertyDeclaration(declaration) && !hasStaticModifier(declaration) && (noImplicitAny || isInJSFile(declaration))) { // We have a property declaration with no type annotation or initializer, in noImplicitAny mode or a .js file. // Use control flow analysis of this.xxx assignments in the constructor to determine the type of the property. const constructor = findConstructorDeclaration(declaration.parent); diff --git a/tests/baselines/reference/staticVisibility2.errors.txt b/tests/baselines/reference/staticVisibility2.errors.txt new file mode 100644 index 0000000000000..b217a0a3fdd74 --- /dev/null +++ b/tests/baselines/reference/staticVisibility2.errors.txt @@ -0,0 +1,15 @@ +tests/cases/compiler/staticVisibility2.ts(2,12): error TS7008: Member 'sideLength' implicitly has an 'any' type. +tests/cases/compiler/staticVisibility2.ts(4,14): error TS2576: Property 'sideLength' is a static member of type 'Square' + + +==== tests/cases/compiler/staticVisibility2.ts (2 errors) ==== + class Square { + static sideLength; + ~~~~~~~~~~ +!!! error TS7008: Member 'sideLength' implicitly has an 'any' type. + constructor(sideLength: number) { + this.sideLength = sideLength; + ~~~~~~~~~~ +!!! error TS2576: Property 'sideLength' is a static member of type 'Square' + } + } \ No newline at end of file diff --git a/tests/baselines/reference/staticVisibility2.js b/tests/baselines/reference/staticVisibility2.js new file mode 100644 index 0000000000000..70ffb3a9f183e --- /dev/null +++ b/tests/baselines/reference/staticVisibility2.js @@ -0,0 +1,15 @@ +//// [staticVisibility2.ts] +class Square { + static sideLength; + constructor(sideLength: number) { + this.sideLength = sideLength; + } +} + +//// [staticVisibility2.js] +var Square = /** @class */ (function () { + function Square(sideLength) { + this.sideLength = sideLength; + } + return Square; +}()); diff --git a/tests/baselines/reference/staticVisibility2.symbols b/tests/baselines/reference/staticVisibility2.symbols new file mode 100644 index 0000000000000..021d5833c4ad8 --- /dev/null +++ b/tests/baselines/reference/staticVisibility2.symbols @@ -0,0 +1,15 @@ +=== tests/cases/compiler/staticVisibility2.ts === +class Square { +>Square : Symbol(Square, Decl(staticVisibility2.ts, 0, 0)) + + static sideLength; +>sideLength : Symbol(Square.sideLength, Decl(staticVisibility2.ts, 0, 14)) + + constructor(sideLength: number) { +>sideLength : Symbol(sideLength, Decl(staticVisibility2.ts, 2, 16)) + + this.sideLength = sideLength; +>this : Symbol(Square, Decl(staticVisibility2.ts, 0, 0)) +>sideLength : Symbol(sideLength, Decl(staticVisibility2.ts, 2, 16)) + } +} diff --git a/tests/baselines/reference/staticVisibility2.types b/tests/baselines/reference/staticVisibility2.types new file mode 100644 index 0000000000000..6243cd21a2fde --- /dev/null +++ b/tests/baselines/reference/staticVisibility2.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/staticVisibility2.ts === +class Square { +>Square : Square + + static sideLength; +>sideLength : any + + constructor(sideLength: number) { +>sideLength : number + + this.sideLength = sideLength; +>this.sideLength = sideLength : number +>this.sideLength : any +>this : this +>sideLength : any +>sideLength : number + } +} diff --git a/tests/cases/compiler/staticVisibility2.ts b/tests/cases/compiler/staticVisibility2.ts new file mode 100644 index 0000000000000..e27b63c38f92b --- /dev/null +++ b/tests/cases/compiler/staticVisibility2.ts @@ -0,0 +1,7 @@ +// @noImplicitAny: true +class Square { + static sideLength; + constructor(sideLength: number) { + this.sideLength = sideLength; + } +} \ No newline at end of file