Skip to content

Variable and Constant declarations (block/global) should be declared on common js/umd/amd/System exports same as functions #41360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
igorzg opened this issue Nov 1, 2020 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@igorzg
Copy link

igorzg commented Nov 1, 2020

TypeScript Version: 4.x, 3.x, 2.x

Search Terms:
variable / constant declarations on exports ignored using commonjs, amd, umd, System module on ES2015, ES2016, ES2017, ES2018, ES2019, ES2020
Expected behavior:
Variable and Constant declarations (block/global) should be declared on exports (it should behave same as function declarations)

let Injectable = () => console.log(Injectable.name);
exports.Injectable = Injectable;

var Injectable = () => console.log(Injectable.name);
exports.Injectable = Injectable;

const Injectable = () => console.log(Injectable.name);
exports.Injectable = Injectable;

Actual behavior:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Injectable = void 0;
exports.Injectable = () => console.log(exports.Injectable.name);

Related Issues:
No

Code

export let Injectable = () => console.log(Injectable.name);
export const Injectable = () => console.log(Injectable.name);
export var Injectable = () => console.log(Injectable.name);

typescript ignores var, let, const declarations on export which should not be the case.

Output
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Injectable = void 0;
exports.Injectable = () => console.log(exports.Injectable.name);
Compiler Options
{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "moduleResolution": 2,
    "target": "ES2015",
    "jsx": "React",
    "module": "commonjs"
  }
}

Playground Link: Provided

@igorzg igorzg changed the title Variable and Constant declarations (block/global) should be declared on common js exports same as functions Variable and Constant declarations (block/global) should be declared on common js/umd/amd/System exports same as functions Nov 1, 2020
@MartinJohns
Copy link
Contributor

Duplicate of #39819.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Nov 11, 2020
@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants