1

The follow constructs generate the same js and type hints. Is there any difference between the two, and when should one be used over the other?

Import alias:

import mod = require('./mod');
import Foo = mod.Foo;
var foo = new Foo();

Variable alias:

import mod = require('./mod');
var Foo = mod.Foo;
var foo = new Foo();

Output from both w/commonjs:

var mod = require('./mod');
var Foo = mod.Foo;
var foo = new Foo();

1 Answer 1

2

Is there any difference between the two, and when should one be used over the other?

Yes. import also brings it into the type declaration space. This is only significant for TypeChecking and not significant in the generated JS.

See https://stackoverflow.com/a/26983363/390330 for an example.

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

Comments

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.