I am trying to extend the global
in node.js, using typescript.
For this, I've created the following structure:
File content of index.d.ts
:
import socketio from 'socket.io';
declare namespace NodeJS {
interface Global {
sockets: socketio.Socket[];
}
}
In my tsconfig.json file I provided: "typeRoots": [ "./node_modules/@types", "./@types"]
But I still can't use global.sockets
. How to fix it?
Please note that if I would write index.d.ts
as:
declare namespace NodeJS {
interface Global {
sockets: any[];
}
}
Then I would be able to access global.sockets