-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already createdNeeds ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Say I'm writing a declaration file for an external library that both exposes a global and supports CommonJS. According to the handbook I would write that like this:
module zoo {
function open(): void;
}
declare module "zoo" {
export = zoo;
}
And then the usage would be this:
// Either
import x = require('zoo');
x.open();
// or
zoo.open();
The problem is that while the above would compile when using external modules, at run-time it would fail since the "zoo" identifier doesn't actually exist. Is there any way to write declaration files such that you can split them into two separate files (one for internal, one for external) so that you only reference the one you intend on using but not actually duplicate the definitions in those files? For example
// zoo.d.ts
declare module "zoo" {
export = zoo;
}
// zoo-internal.d.ts
/// <reference path="zoo.d.ts" />
module zoo {
// this doesn't work but illustrates what I'm trying to accomplish
import zoo = require('zoo')
export = zoo;
}
Or any thoughts on another way to accomplish the same goals in a single file?
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already createdNeeds ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.This issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScriptAn idea for TypeScript