The Wayback Machine - https://web.archive.org/web/20201129105807/https://github.com/microsoft/TypeScript/issues/41653
Skip to content
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

Enum Keys in Destructure Prevents ES6 Function Convert with --target ES5 #41653

Open
MichaelPastuch opened this issue Nov 23, 2020 · 0 comments · May be fixed by #41703
Open

Enum Keys in Destructure Prevents ES6 Function Convert with --target ES5 #41653

MichaelPastuch opened this issue Nov 23, 2020 · 0 comments · May be fixed by #41703

Comments

@MichaelPastuch
Copy link

@MichaelPastuch MichaelPastuch commented Nov 23, 2020

TypeScript Version: 4.0.5, 4.1.2, and 4.2.0-dev.20201123

Search Terms: es5 target, arrow function, enum destructure

Code

const enum MyTest {
	first = "first",
	second = "second"
}

// Arrow function not converted to ES5
const { [MyTest.first]: firstArrow, [MyTest.second]: secondArrow } = (() => {
	return { [MyTest.first]: [1], [MyTest.second]: [0] };
})();
console.debug(firstArrow, secondArrow);

// Arrow function converted to ES5
const numGroups = (() => {
	return { [MyTest.first]: [1], [MyTest.second]: [0] };
})();
// Destructure works as intended
const { [MyTest.first]: firstFunction, [MyTest.second]: secondFunction } = numGroups;
console.debug(firstFunction, secondFunction);

Expected behavior: With --target es5, both es6 arrow functions should be converted to anonymous functions

Actual behavior: The first arrow function is not converted. Replacing the enums in the destructure keys fixes the function, as does using TypeScript 3.7.5.

Playground Link: Playground link

Related Issues:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants
You can’t perform that action at this time.