Why do I get an implicit 'any' error on a private getter in my .d.ts files?

172 views Asked by At

I upgraded my dependencies via npm install or something and now TypeScript 3.6 reports a weird error message

Property 'myGetter' implicitly has type 'any', because its get accessor lacks a return type annotation.

I don't understand what's happening. My code hasn't changed at all. Moving to TypeScript 3.7 fixes the problem, and TypeScript 3.5, I get the same error along with a new error:

An accessor cannot be declared in an ambient context.
1

There are 1 answers

0
Daniel Rosenwasser On

Upgrading TypeScript to 3.6.5, or ideally a newer version, will fix the issue. Just run

npm install typescript

or if you really need to stay locked to TypeScript 3.6

npm install [email protected]

The likely reason why this is happening is that one of your dependencies started using TypeScript 3.7 or newer.

TypeScript 3.7 started generating get accessors in .d.ts files, but left their types off for private members. TypeScript 3.6.4 assumed this was an error under noImplicitAny. That's a bug that was fixed in 3.6.5 and TypeScript 3.7.