Skip to content

"Implicitly has type 'any'" when type annotation is providedΒ #50864

Closed as not planned

Description

Bug Report

πŸ”Ž Search Terms

implicit any, filter object properties by type, key remapping

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type BooleanProperties<T> = T extends any ? { 
  [K in keyof T as T[K] extends boolean ? K : never]: boolean;
} : never;

class Foo {
  booleansOnly: BooleanProperties<this> = undefined!; // Omitted..
  
  getString<F extends (someUsefulData: any) => any>(fn: F) : string {
    return undefined!; // Omitted..
  };

  aBoolean = true;
  
  definitelyAString = this.getString(() => this.booleansOnly.aBoolean);
}

πŸ™ Actual behavior

Error: 'definitelyAString' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.

πŸ™‚ Expected behavior

Since "getString" method has an explicit return type (string), in my opinion "type annotation" is provided, and the error should not be thrown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions