Schodemeiss
Schodemeiss

Reputation: 1174

TypeScript: Can I mix using "import * from" and "require(*)"

Is it ok in TypeScript to mix these too 'include' types?

import { SomeType, someFunc } from "./MyThings";

And:

import events = require('events');

The first would be a TypeScript module with an export or two... and the second is just a node module called events (I guess this could be anything pulled in from NPM too).

Am I ok to mix these two conventions in a single TypeScript file?

Upvotes: 16

Views: 10230

Answers (1)

James Monger
James Monger

Reputation: 10665

Yes, this is acceptable in TypeScript.

When using the import foo = require('foo');, you must have a module 'foo' declared with declare module 'foo', typically in a .d.ts file.

This is typically covered in node.d.ts.

Upvotes: 5

Related Questions