This project is read-only.

Typescript Imports

Topics: Language Specification
Feb 5, 2014 at 1:54 AM
I love the fact that you can assign imports in typescript as follows:
import ClassNameRef = module.path.ClassName;

and then reference module.path.ClassName simply by typing ClassNameRef.

But it would be that tiny bit faster and tidier if the typescript compiler was updated so if you didn't specify a name it would just default to the class name..

import module.path.ClassName;

module.path.ClassName would be equal to ClassName

Can anyone think of any reasons why this would be a bad idea?
Feb 5, 2014 at 2:35 PM
I think it would be an excellent idea but there are a lot of small details here. First of all the Harmony spec doesn't have special rules for imports - it's all path based (see: ) and TS strives to be ES6 compatible.

Second thing is that I think it should work for both internal and external modules. I've got a lot of imports that look like that:
import DataSource = require('data/DataSource');
import DataSourceSync = require('data/DataSourceSync');
import HttpServiceDataSource = require('data/sources/HttpServiceDataSource');
import IndexedDbDataSource = require('data/sources/IndexedDbDataSource');
and it would be nice if they could be written in a more compact form:
import data.DataSource;
import data.DataSourceSync;
import data.sources.HttpServiceDataSource;
import data.sources.IndexedDbDataSource;
but while conversion is easy in this example what would it look like for this one?
import Actions = require('../../model/Actions');
tsc doesn't have a concept of base path that all import paths start from as far as I understand. Or more precisely require('test') is the same as require('./test') and that's not the same in requirejs (require.js has a base path that's used to convert relative ones - like 'test' in this example).