Skip to content

This-function parameter inference fails in object with other typing features #10461

Closed
@HerringtonDarkholme

Description

@HerringtonDarkholme

This may relate to #10288

TypeScript Version: 2.0.0, installed via typescript@beta

Code
All code under --noImplicitThis flag.

function plainThisBound(m: {[k:string]: (this: string) => string}) {}

plainThisBound({
  method() {
    return this.substr(0) // no error
  }
})

function polymorphicThisBound(m: {[k:string]: <V>(this: string) => V}) {}
polymorphicThisBound({
  method() {
    return this.substr(0) // error in noImplicitThis
  }
})

function unionThisBound(m: {[k:string]: (this: string) => string} & {method(): string}) {}
unionThisBound({
  method() {
    return this.substr(0) // error in noImplicitThis
  }
})

Expected behavior:
All three example should compile, if this parameter is inferred on call site
Or no example should compile, if this must be explicitly annotated

Actual behavior:
Only the first example compiles.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions