xxxxxxxxxx
/* Create global.d.ts */
// extend the global object with "declare global"
declare global {
type Example = {
foo: string
bar: number
}
}
// type "Example" will now be available anywhere without import
xxxxxxxxxx
/* For "typescript" starting at version 4.9.3 the file global.d.ts
need declared as below and your name can be "global.d.ts" or "index.d.ts". */
declare global {
var varName: string
function sample(value: string): string;
}
export {}
/* Using in another fileX.ts file */
global.varName = "Your name";
global.sample = function (value: string): string {
return `Yout name is ${value}`;
};
/* Using in somewhere else fileY.ts */
const value = sample(varName)
console.log(value) // This exemple It's the returns "Yout name is Your name"
// Please register your like
xxxxxxxxxx
declare global {
interface Window {
myGlobalFunction: myGlobalFunction
}
}