Skip to content
Merged
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 src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions tests/baselines/reference/staticVisibility2.errors.txt
Original file line number Diff line number Diff line change
@@ -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'
}
}
15 changes: 15 additions & 0 deletions tests/baselines/reference/staticVisibility2.js
Original file line number Diff line number Diff line change
@@ -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;
}());
15 changes: 15 additions & 0 deletions tests/baselines/reference/staticVisibility2.symbols
Original file line number Diff line number Diff line change
@@ -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))
}
}
18 changes: 18 additions & 0 deletions tests/baselines/reference/staticVisibility2.types
Original file line number Diff line number Diff line change
@@ -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
}
}
7 changes: 7 additions & 0 deletions tests/cases/compiler/staticVisibility2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @noImplicitAny: true
class Square {
static sideLength;
constructor(sideLength: number) {
this.sideLength = sideLength;
}
}