Skip to content

Instantly share code, notes, and snippets.

@dhermes
Created March 7, 2019 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhermes/aa2af901a9612134c6478cc84e5e8686 to your computer and use it in GitHub Desktop.
Save dhermes/aa2af901a9612134c6478cc84e5e8686 to your computer and use it in GitHub Desktop.
Understanding `export =`

This is based on the export = and import = require() section in the modules page of the TypeScript handbook.

> const exportEquals = require('./exportEquals');
undefined
> exportEquals(2)
20
> exportEquals.MARKER
'HELLO'
"use strict";
function doMath(value) {
return value + 18;
}
doMath.MARKER = 'HELLO'; // Would rather do `export.MARKER = 'HELLO'`.
module.exports = doMath;
function doMath(value: number): number {
return value + 18
}
export = doMath
doMath.MARKER = 'HELLO' // Would rather do `export.MARKER = 'HELLO'`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment