question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Implicitly has type 'any'" when type annotation is provided

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
RyanCavanaughcommented, Sep 26, 2022

There’s a good discussion about this in #45213

0reactions
MartinJohnscommented, Sep 21, 2022

Maybe adding some kind of syntax to provide Typescript instructions on how to handle circularity errors

It mentioned the option to add a type annotation in the error message.

I hope in the future Typescript will provide a way to handle this kind of sistuations

As far as I know the compiler would have to be rewritten basically from scratch, and introduce a two-phase type check. Very unlikely to happen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'this' implicitly has type 'any' because it does not have a type ...
json , I get this error for the following code: 'this' implicitly has type 'any' because it does not have a type annotation....
Read more >
'this' implicitly has type 'any' error in TypeScript | bobbyhadz
The error "this implicitly has type any" occurs when we use the this keyword outside of classes or in functions where the type...
Read more >
'this' implicitly has type 'any' because it does not ... - You.com
Answers to typescript - 'this' implicitly has type 'any' because it does not have a type annotation - has been solverd by 3...
Read more >
Documentation - Everyday Types - TypeScript
Parameter Type Annotations ... // Would be a runtime error if executed! ... Even if you don't have type annotations on your parameters,...
Read more >
How to fix this error? "'this' implicitly has type 'any' because it ...
How to fix this error? "'this' implicitly has type 'any' because it does not have a type annotation.ts(2683)".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found