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

Simple Typescript: declare static property errors on build (but static declare works) #11145

Closed
dcporter opened this issue Feb 14, 2020 · 1 comment · Fixed by #11146
Closed
Assignees
Labels
area: typescript i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser

Comments

@dcporter
Copy link

Bug Report

Current Behavior

Building simple typescript with declare static properties fails. Switching to static declare succeeds. Both are valid TypeScript syntax. Prettier enforces declare static by default (which matches how I instinctively write it), fwiw.

Input Code

class Foo {
   declare static bar: string;
}

Expected behavior/code
It should compile. Instead I get the following error:

Error: Module build failed (from […]/node_modules/babel-loader/lib/index.js):
SyntaxError: […]/Foo.ts: Unexpected token (24:19)

  22 | 
  23 | class Foo {
> 24 |     declare static bar: string;
     |                    ^
  25 | }
  26 | 
  27 | 
    at Object.raise ([…]/node_modules/@babel/parser/lib/index.js:6983:17)
    at Object.unexpected ([…]/node_modules/@babel/parser/lib/index.js:8376:16)
    at Object.parseClassMemberWithIsStatic ([…]/node_modules/@babel/parser/lib/index.js:11615:12)
    at Object.parseClassMemberWithIsStatic ([…]/node_modules/@babel/parser/lib/index.js:5978:11)
    at Object.parseClassMember ([…]/node_modules/@babel/parser/lib/index.js:11508:10)
    at Object.parseClassMember ([…]/node_modules/@babel/parser/lib/index.js:5952:11)
    at […]/node_modules/@babel/parser/lib/index.js:11463:14
   [much more stack]

This feature was introduced in #10484.

Babel Configuration (babel.config.js, .babelrc, package.json#babel, cli command, .eslintrc)

The relevant bit: "@babel/plugin-transform-typescript", { allowDeclareFields: true }

Environment

  System:
    OS: macOS 10.15.3
  Binaries:
    Node: 12.14.1 - /usr/local/bin/node
    Yarn: 1.21.1 - /usr/local/bin/yarn
    npm: 6.13.4 - /usr/local/bin/npm
  Monorepos:
    Yarn Workspaces: 1.21.1
    Lerna: 2.11.0
  npmPackages:
    @babel/cli: ^7.6.4 => 7.7.0 
    @babel/plugin-proposal-class-properties: ^7.7.0 => 7.7.0 
    @babel/plugin-proposal-decorators: ^7.7.0 => 7.7.0 
    @babel/plugin-proposal-nullish-coalescing-operator: ^7.4.4 => 7.4.4 
    @babel/plugin-proposal-optional-chaining: ^7.7.5 => 7.7.5 
    @babel/preset-typescript: ^7.7.2 => 7.7.4 
    eslint: ^5.16.0 => 5.16.0 
    lerna: ^2.0.0 => 2.11.0 
@babel-bot
Copy link
Collaborator

Hey @dcporter! 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."

@JLHwung JLHwung self-assigned this Feb 15, 2020
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label May 23, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: typescript i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants