Skip to content

noImplicitAny option do not generate an error when the function generating this coercicion is passed as a function parameter. #8773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sledorze opened this issue May 23, 2016 · 1 comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@sledorze
Copy link

TypeScript Version:

1.9.0-dev.20160523-1.0

Code (with noImplicitAny option turned ON)

class Foo {

  identity<T>(x: T): T {
    return x
  }

  bar<T>(g: (a: T) => T): (a: T) => T {
    return g;
  }

  constructor() {
    let v = a => this.identity(a)
    let w = this.bar(a => this.identity(a))
  }
}

Expected behavior:

The line binding an expression to w should error stating that 'a' implicitely has an 'any' type
OR (better)
v and w should be polymorphic (and have type (a:T) => T

Actual behavior:

v and w both have type (a:{}) => {} AND only the expression of v generates an error stating that 'a' implicitly has an 'any' type. (noImplicitAny option turned on)

@mhegazy
Copy link
Contributor

mhegazy commented May 23, 2016

The current behavior looks right to me.

  • a in let v = a => this.identity(a) implicitly has the type any,as there is no type annotation or a contextual type.
  • v does not have the type any, it is (a:any) => any, and it is not implicit. so no error should be reported here.
  • a in this.bar(a => this.identity(a)) has a contextual type, that is the result of the inference for T, which happens to get no useful type, so falls back to the {}. and a gets that. again nothing implicit about this. see Type inference defaults to '{}' in call sites. #5254 for this.
  • w does not have the type any, it is (a:{}) => {}, and it is not implicit. so no error should be reported here.

i think #5254 is the real culprit and not implictAny warnings.

@mhegazy mhegazy closed this as completed May 23, 2016
@mhegazy mhegazy added the Working as Intended The behavior described is the intended behavior; this is not a bug label May 23, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

2 participants