Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 666
Schodemeiss Avatar asked Apr 13 '16 08:04

Schodemeiss


1 Answers

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.

like image 95
James Monger Avatar answered Sep 19 '22 08:09

James Monger