Search code examples
angularangular9

After upgrade to Angular 9 cannot find variable in typings file


I have a reference to an external logging component (referenced in a js file), which I have defined in a typings file

typings.d.ts

declare var LogglyTracker;

I have upgraded my angular application from version 8 to 9, and now when I run ng build, I get the following error

ERROR in src/app/error/loggly.service.ts:13:29 - error TS2304: Cannot find name 'LogglyTracker'.

Does anyone know what the recommended way to fix this problem is? This code worked fine in Angular 8.

@Injectable()
export class LogglyLoggerService {

// https://github.com/loggly/loggly-jslogger
private loggly: any = new LogglyTracker(); //!! Error here
}

Solution

  • Well for me the resolution was to add the following to the top of service file:

    /// <reference path="../../typings.d.ts" />
    

    reference is apparently another way to import type definitions into code, more info here