S
S
Svyatoslav Khusamov2017-03-11 09:56:50
Node.js
Svyatoslav Khusamov, 2017-03-11 09:56:50

How do I import the ErrnoException type from @types/node?

@types/node defines type ErrnoException

declare namespace NodeJS {
   ...
    export interface ErrnoException extends Error {
        errno?: number;
        code?: string;
        path?: string;
        syscall?: string;
        stack?: string;
    }
...

I'm trying to import it in my program:
import { ErrnoException } from '@types/node';
To use it later, for example:
server.on('error', (error: ErrnoException) => {
        if (error.syscall !== 'listen') reject(error);

The compiler throws an error:
error TS2306: File '/home/ubuntu/workspace/node_modules/@types/node/index.d.ts' is not a module.

How do I properly import types from @types/* ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Svyatoslav Khusamov, 2017-03-11
@khusamov

Found the answer. It turns out the type is already imported in some miraculous way. Just had to correctly name it NodeJS.ErrnoException

server.on('error', (error: NodeJS.ErrnoException) => {

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question