Omit "require" and "exports" from TypeScript emitted AMD dependencies

Viewed 2009

Given the following TypeScript file,

export = {};

tsc (with "module": "amd") will emit:

define(["require", "exports"], function (require, exports) {
  "use strict";
   return {};
});

However, I would rather it emit

define([], function() {
    "use strict";
    return {};
});

... and only include require or exports if I explicitly import them, i.e.

import relativeRequire = require("require");

Is there any way to tell TypeScript not to emit require and exports in emitted AMD modules (i.e. ask it not to use the CommonJS simplified wrapping)?

Notes:

  • The output I propose is fully compliant with the AMD spec.
  • An empty dependencies array is the only way for the module to have zero dependencies (as opposed to omitting the dependencies array, which implies the require, exports, and module dependencies).

UPDATE 4 July 2017: Looks like this is actually an open issue in the TypeScript GitHub repo: https://github.com/Microsoft/TypeScript/issues/669

Any ideas for a pragmatic workaround until this gets implemented? (Or, is there actually some way to make TypeScript do this?)

2 Answers
Related