0

I have a logger function in logger.ts

export const Logger=(message:string, module?:string, method?:string)=>{
    console.log(`${module} ${message}`)
}

In types/global.d.ts

declare global {
    var Log: any;
}
export {}

In index.ts

import { Logger } from './src/utils/logger';
global.Log=Logger;
global.Log("Hello world");

It works without any problem. But in global.Log i can't see the parameters and intellisense not working.

How can I see parameters for global.Log?

1 Answer 1

1

I believe Intellisense is not working because the variable Log is of any type. Try defining global as below:

declare global {
    var Log: (message: string, module?: string, method?: string) => void;
}
export {};

Intellisense will need a specific type (not any or unknown) in order to suggest parameters.

Also, there is no need to prefix Log with global (i.e. global.Log) as Log is in the global context (accessible from anywhere), and it is not possible to use global.Log - global is not a variable.

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

3 Comments

Global object defined in Node Js and you can reach it from everywhere. For details
If I use without global, I got an error ReferenceError: Log is not defined.
Finally I use global.Log when I assign the method. Otherwise I can directly use Log.

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.