Ambiant definitions not loaded after Angular9 migration

46 Views Asked by At

I just migrated a project from Angular 8 to 9. Migration succeeded however since then it looks like my ambiant typings are not picked up by the compiler anymore.

My vendor.d.ts file looks like :

interface JQuery {
  select2(p?: any): JQuery;
  trumbowyg(options?: TrumbowygOptions | any, ...any): JQuery;
}
interface TrumbowygOptions {
  btns: string[][];
  autogrow?: boolean;
  autogrowOnEnter?: boolean;
  svgPath?: string;
  resetCss: boolean;
}

And it is referenced in my main tsconfig.json like this :

 "typeRoots": [
      "node_modules/@types",
      "src/app/vendor.d.ts"
    ],

I am stuck with errors like :

error TS2551: Property 'select2' does not exist on type 'JQuery<HTMLElement>'. Did you mean 'select'?

72     this._multiSelectJQuery.select2({ theme: 'bootstrap' });
                               ~~~~~~~

I found that TS 3.6 introduced more strict checks regarding ambiant type definitions. I did various tests like using the declare keyword (https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-6.html#ambient-classes-and-functions-can-merge)

1

There are 1 best solutions below

0
Binary9 On

As mentionned here : https://github.com/angular/angular-cli/issues/16905

Adding the following snippet in my tsconfig.app.json solved the issue :

"include": ["**/*.d.ts"]