mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
not narrow static property without type annotation in constructor. (#39252)
* fix #39226 * fix lint.
This commit is contained in:
parent
eb2f4e2337
commit
4601a786aa
@ -7825,7 +7825,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);
|
||||
|
||||
15
tests/baselines/reference/staticVisibility2.errors.txt
Normal file
15
tests/baselines/reference/staticVisibility2.errors.txt
Normal file
@ -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
tests/baselines/reference/staticVisibility2.js
Normal file
15
tests/baselines/reference/staticVisibility2.js
Normal file
@ -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
tests/baselines/reference/staticVisibility2.symbols
Normal file
15
tests/baselines/reference/staticVisibility2.symbols
Normal file
@ -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
tests/baselines/reference/staticVisibility2.types
Normal file
18
tests/baselines/reference/staticVisibility2.types
Normal file
@ -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
tests/cases/compiler/staticVisibility2.ts
Normal file
7
tests/cases/compiler/staticVisibility2.ts
Normal file
@ -0,0 +1,7 @@
|
||||
// @noImplicitAny: true
|
||||
class Square {
|
||||
static sideLength;
|
||||
constructor(sideLength: number) {
|
||||
this.sideLength = sideLength;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user