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..
module.path.ClassName would be equal to ClassName
Can anyone think of any reasons why this would be a bad idea?
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:
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).