Search code examples
typescripttypescript1.8

TypeScript Compile Options: module vs target


Trying to have some basic understanding about module and target.

I would like to know the difference between module and target compile options in a typical tsconfig.json

{
    "compilerOptions": {
        "module": "es6",
        "sourceMap": true,
        "target": "es6"
    }
}

What happens if I provide the following options:

module: commonjs, target: es6

module: es6, target: commonjs

module: commonjs, target: commonjs


Solution

  • A more detailed explanation is here : Understanding "target" and "module" in tsconfig


    See also: Understanding "target" and "module" in tsconfig.

    Here is a quote from the documentation on compiler options:

    --target

    Specify ECMAScript target version: 'es3' (default), 'es5', or 'es6'.

    --module

    Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es6', or 'es2015'.

    • Only 'amd' and 'system' can be used in conjunction with --outFile.
    • 'es6' and 'es2015' values may be used when targeting ES5 or lower.