"Implicitly has type 'any'" when type annotation is provided
See original GitHub issueBug 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:
- Created a year ago
- Comments:5 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
There’s a good discussion about this in #45213
It mentioned the option to add a type annotation in the error message.
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.