czerny czerny - 2 years ago 358
Node.js Question

How to import node module in Typescript without type definitions?

When I try to import node.js module in Typescript like this:

import co = require('co');
import co from 'co';

without providing type definitions, both lines reports same error:

error TS2307: Cannot find module 'co'.

How to import it correctly?

Answer Source

The trick is to use purely JavaScript notation:

const co = require('co');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download