0

I try to write some test unit with the following global variable

declare global{
  namespace NodeJS {
    interface Global {
      signin(): string;
    }
  }
}


global.signin = () => { 

  return ["test"] ;

};

I got error on the global.signin:

"Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature."

ofir
  • 1
  • 1
  • 1
    Does this answer your question? [How do I prevent the error "Index signature of object type implicitly has an 'any' type" when compiling typescript with noImplicitAny flag enabled?](https://stackoverflow.com/questions/32968332/how-do-i-prevent-the-error-index-signature-of-object-type-implicitly-has-an-an) – lbsn Aug 03 '21 at 11:00
  • `signin` returns `["test"]` which is `string[]`, not `string`. After fixing that, your code works just fine for me. I guess your real problem is somewhere outside the code you've shared. – funkizer Aug 03 '21 at 11:15
  • Question arises though: Why do you need to make something global anyway? Why not some singleton service or something. Or Dependency Injection. There are many better ways to make something "global". – funkizer Aug 03 '21 at 11:17
  • @funkizer adding sting[] doesn't change the error – ofir Aug 03 '21 at 21:14
  • @funkizer can you give me more information for better ways to do that? I want to make the global for the test unit. To be able to use global.signin function – ofir Aug 03 '21 at 21:15

0 Answers0