Oliver Ilmjärv
Oliver Ilmjärv

Reputation: 341

Typescript file cannot find the declarations defined in .d.ts file

I'm trying to declare some global window functions for my typescript plugin. The functions are defined in the browser and i want them to be declared in the code aswell.

For some odd reason my code cant find those declarations from that file. The declarations are in @types/globals.d.ts file.

Do i need to configure the tsconfig.json file or something like that. Cant seem to find a straight answer from anywhere else.

Just in case, here is my tsconfig.json file

{ 
    "compilerOptions": {
      "outDir": "./dist/",
      "noImplicitAny": true,
      "module": "es6",
      "target": "es5",
      "strict": true,
      "sourceMap": true,
      "allowJs": true,
      "moduleResolution": "node"
    }
}

globals.d.ts

enter image description here

index.ts

enter image description here

Here's the error message

enter image description here

Thanks in advance.

Upvotes: 1

Views: 516

Answers (1)

Oliver Ilmjärv
Oliver Ilmjärv

Reputation: 341

Correct solution was to redefine the window interface. Now the rest of the files automatically detect the types.

declare global {
  interface Window {
    section: string;
    __t: (string: string) => string;
    apiSessionKey: string;
    companyData: CompanyData;
    conf_dateformat: string;
    country: string;
    customerCode: string;
    decimalSymbol: string;
    employeeEmail: string;
    employeeID: number;
    employeeName: string;
    formAttributes: any[];
    gdprFeaturesEnabled: boolean;
    isExistingRecord: boolean;
    page_lang: string;
    priceDecimals: number;
    recordID: number;
    subsection: string;
    thousandsSeparator: string;
    userGroupID: number;
    userGroupName: string;
    userID: number;
    userName: string;
  }
}

Upvotes: 2

Related Questions