Skip to content

Instance property used in reassigning method causes implicit any in checkJs #35099

Closed
@DanielRosenwasser

Description

@DanielRosenwasser
// ./foo.ts

class Foo {
    constructor() {
        this.foo = "Hello";
    }
    slicey() {
        this.foo = this.foo.slice();
    }
}
// ./tsconfig.json

{
  "compilerOptions": { "strict": true },
  "files": ["./foo.ts"]
}

Current Behavior

'foo' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.ts(7022)

Proposed Behavior

If an implicit any is going to be inferred, but foo has an initializer in the constructor, it should always infer the type from the initializer.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issuecheckJsRelates to checking JavaScript using TypeScript

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions