You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes it happens so that some code logically belongs in one module, but there is just too much of it to put in one file. For example, here is my use case:
// base.ts
export interface SomeCoreType { ... }
export interface MyStandardAjaxResponse { ... }
export function doAjax( url: string, onSuccess: (r: MyStandardAjaxResponse) => void ) { ... }
export interface User { ... }
export function isUserOk( u: User ) { return ... }
// and so on
// customer.ts
import b = module( "./base.ts" );
export class Customer {
constructor( id: number, someArg: b.SomeCoreType ) {
b.doAjax( '/api/getCustomer', r => this.loadData( r ) );
}
loadData( r: b.MyStandardAjaxResponse ) { ... }
}
// and so on
Over time, that base.ts file tends to grow with all kinds of enums, utility functions, common types, etc. At some point, it becomes so large that I want to partition it across several files. For example, I'd like to extract SomeCoreType into its own module coreType.ts, then extract MyStandardAjaxResponse and doAjax into ajax.ts, and extract User and isUserOk into user.ts. Just for my sanity's sake. Makes sense?
But if I do that, I'll have to import a gazillion of modules every time.
So my next logical step - consolidate them all back into base.ts:
// base.ts
import _coreType = module("./coreType");
export var CoreType = _coreType;
import _ajax = module("./ajax");
export var Ajax = _ajax;
import _user = module("./user");
export var User = _user;
// and so on
That's better. Now I only have to import base.ts.
However, I still have to write b.Ajax.doAjax instead of just b.doAjax. That's inconvenient.
But an even bigger issue is that now I can't use interfaces declared in those modules. TypeScript just doesn't pick them up.
What I'd like to be able to do is something like this:
import Ajax = module("./ajax");
export Ajax.*;
Or, perhaps, the infamous export import:
export import Ajax = module("./ajax");
Or, maybe, something like:
reexport module("./ajax");
And the output code could look something like this:
define(['module', 'exports', './ajax'], function(module, exports, __ajax__) {
for( var k in __ajax__ ) exports[k] = __ajax__[k];
});
The text was updated successfully, but these errors were encountered:
Yes, the use case is exactly the same.
Although, I must note that my proposal (i.e. have a separate "bundling" file) nicely solves the "module boundaries" issue.
Sometimes it happens so that some code logically belongs in one module, but there is just too much of it to put in one file. For example, here is my use case:
Over time, that base.ts file tends to grow with all kinds of enums, utility functions, common types, etc. At some point, it becomes so large that I want to partition it across several files. For example, I'd like to extract SomeCoreType into its own module coreType.ts, then extract MyStandardAjaxResponse and doAjax into ajax.ts, and extract User and isUserOk into user.ts. Just for my sanity's sake. Makes sense?
But if I do that, I'll have to import a gazillion of modules every time.
So my next logical step - consolidate them all back into base.ts:
That's better. Now I only have to import base.ts.
However, I still have to write b.Ajax.doAjax instead of just b.doAjax. That's inconvenient.
But an even bigger issue is that now I can't use interfaces declared in those modules. TypeScript just doesn't pick them up.
What I'd like to be able to do is something like this:
Or, perhaps, the infamous export import:
Or, maybe, something like:
And the output code could look something like this:
The text was updated successfully, but these errors were encountered: