Is there a way to replace the any
type with NetworkInterfaceInfo[]
type in this code snippet?
Unfortunately, I am unable to import @types/node
because of an issue mentioned here: How to fix "@types/node/index.d.ts is not a module"?
Here is the original code:
import { networkInterfaces } from 'os';
// array.prototype.concat use type any
const getLocalExternalIP = () => ([] as any).concat(...Object.values(networkInterfaces()))
.find((info: any) => { // any
return info.family === 'IPv4' && !info.internal;
}).address;
export { getLocalExternalIP };
I attempted to rewrite it like this:
...
// Cannot find name 'NetworkInterfaceInfo'.ts(2304)
const getLocalExternalIP = () => ([] as NetworkInterfaceInfo[]).concat( ...
...
Do you have any suggestions on how to avoid using the any type in this specific scenario?