Skip to content

noImplicitAny does not apply to function context #29899

@knpwrs

Description

@knpwrs

TypeScript Version: 3.3.3

Search Terms: noImplicitAny, context

Code

function foo(num: number) {
  this.num = num;
}

Expected behavior:

When I hover over this I should see void as the implicitly inferred type. Ideally this.num would be an error, especially in strict mode.

Actual behavior:

I see any as the implicit type of this. this is always inferred to be any unless I override it in the function signature.

Playground Link:

Bad: https://www.typescriptlang.org/play/index.html#src=type%20Context%20%3D%20%7B%0D%0A%20%20%20%20num%3A%20number%2C%0D%0A%7D%0D%0A%0D%0Afunction%20foo(num%3A%20number)%20%7B%0D%0A%20%20this.num%20%3D%20num%3B%0D%0A%7D

Good: https://www.typescriptlang.org/play/index.html#src=type%20Context%20%3D%20%7B%0D%0A%20%20%20%20num%3A%20number%2C%0D%0A%7D%0D%0A%0D%0Afunction%20foo(this%3A%20Context%2C%20num%3A%20number)%20%7B%0D%0A%20%20this.num%20%3D%20num%3B%0D%0A%7D

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions