1

I want to import a normal javascript module (e.g. vhost) into my node.js typescript file using CommonJS. I can do this with the following line:

import vhost = require('vhost')

We assume that I can't find a .d.ts file on the internet, but I also don't want to write it by myself, so I just use the vhost variable without intellisense.

The compiler complains and complains:

enter image description here

How can I tell that I just want it to be 'dynamic' (like the C# dynamic keyword or 'var' in normal javascript) and use all of the things in the picture above?

I could create a vhost.d.ts file, but I don't know what to write in there:

declare module 'vash' {
    // what to write here?
}

1 Answer 1

4

I found this out while typing the question, it was so easy that it is almost embarrassing, but maybe somebody has this problem too.

Just use var instead of import:

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

This is the official way to do it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.