1

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.

1
  • Pretty sure you can't set TypeScript definition files somewhere else than in a "sibling" file (same directory, same name, .d.ts extension) Commented Aug 4, 2021 at 11:57

1 Answer 1

2

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;
  }
}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.