Trying to add some generic functions globally to the project, but trhows an ReferenceError exception #3905
Answered
by
Julien-R44
wemersonrv
asked this question in
Help
-
Beta Was this translation helpful? Give feedback.
Answered by
Julien-R44
Sep 13, 2022
Replies: 1 comment 1 reply
-
The simplest, and arguably cleanest, would be to just import them. Why not do this, just out of curiosity? If you really want to do that, you'll have to use the "global" object (which is like "window" in the browser) and assign your functions to it. The problem with this is that you'll lose the typing, and you'll have to tell Typescript that these functions exist elsewhere. https://stackoverflow.com/questions/29544417/nodejs-global-functions |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
wemersonrv
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The simplest, and arguably cleanest, would be to just import them. Why not do this, just out of curiosity?
If you really want to do that, you'll have to use the "global" object (which is like "window" in the browser) and assign your functions to it.
The problem with this is that you'll lose the typing, and you'll have to tell Typescript that these functions exist elsewhere.
https://stackoverflow.com/questions/29544417/nodejs-global-functions
https://stackoverflow.com/questions/35074713/extending-typescript-global-object-in-node-js