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

Typescript 3.4 as const not working for arrays #9910

Closed
gcangussu opened this issue Apr 26, 2019 · 2 comments
Closed

Typescript 3.4 as const not working for arrays #9910

gcangussu opened this issue Apr 26, 2019 · 2 comments
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue

Comments

@gcangussu
Copy link

Bug Report

Current Behavior
Babel's typescript transform plugin doesn't support as const with arrays if those have variables or objects into them. The main Typescript implementation does support it.

Input Code
Here's a quick repo reproducing it: https://github.com/gcangussu/babel-typescript-const-error

But basically this is the problem:

function ok() {
  return ['oi', 42] as const; // Type 'readonly ["oi", 42]'
}

function notOk() {
  const a = 'oi';
  const b = 42;
  return [a, b] as const; // SyntaxError: Only literal values are allowed in constant contexts
}

Expected behavior/code

function notOk() {
  const a = 'oi';
  const b = 42;
  return [a, b] as const; // Type 'readonly ["oi", 42]'
}

Babel Configuration (.babelrc, package.json, cli command)

module.exports = {
  presets: ['@babel/preset-typescript'],
};

Environment

  • Babel version: @babel/core 7.4.3, @babel/plugin-transform-typescript 7.4.0
  • Node/npm version: node 11.14, yarn 1.15.2
  • OS: Ubuntu 18.4
  • How you are using Babel:yarn babel index.ts
@babel-bot
Copy link
Collaborator

Hey @gcangussu! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community
that typically always has someone willing to help. You can sign-up here
for an invite.

@nicolo-ribaudo
Copy link
Member

Fixed by #9869

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Jul 26, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Jul 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: bug i: needs triage outdated A closed issue/PR that is archived due to age. Recommended to make a new issue
Projects
None yet
Development

No branches or pull requests

3 participants