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

5.1 introduces TypeScript property errors (too strict?) #2558

Closed
noelrappin opened this issue Apr 26, 2020 · 4 comments
Closed

5.1 introduces TypeScript property errors (too strict?) #2558

noelrappin opened this issue Apr 26, 2020 · 4 comments

Comments

@noelrappin
Copy link

Updating a project from Webpacker 5.0.x to 5.1, and after going through all the upgrade documentation to change to babel-loader. Everything else is up to date...

I have a simple Stimulus controller, defined to start as follows:

import { Controller } from "stimulus"

export default class extends Controller {
  static classes = ["hidden"]
  static targets = ["filterInput", "concert"]

  hiddenClass: string
  concertTargets: HTMLElement[]
  filterInputTarget: HTMLInputElement

  // and so on

Works fine with Webpacker 5.0.1, in 5.1.1 now I am getting TypeError: Cannot set property hiddenClass of #<extended> which has only a getter

It seems as though the babel loader has put TypeScript into strict mode? Or am I missing something?

@gopeter
Copy link
Contributor

gopeter commented Apr 26, 2020

Hmmm I don't think that this is more strict, since it reads the same tsconfig.json as ts-loader and does not bring it's own rules.

I found a few related issues here and here.

@noelrappin
Copy link
Author

Thanks for looking.

Okay, it's not strict, but it is a behavior change, since the code runs fine in 5.0 and fails in 5.1.

@gopeter
Copy link
Contributor

gopeter commented Apr 27, 2020

Thats true, but it's also the "right" way as you can see in the TC39 proposal (got it from this comment). So babel-loader does the right thing actually.

For now, you can fool TS.

I'm not sure if this is going to be resolved anytime soon. Here's a quote from the corresponding babel issue:

At any rate, this is a conflict between the current TC39 class properties proposal and TypeScript properties.

If you declare a property without initializing, you are still declaring the property, and so it must be initialized to undefined according to spec. The type annotation for the property is still being correctly stripped; but the property itself still exists.

@guillaumebriday
Copy link
Member

Is this still an issue?

Feel free to reopen if needed

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

No branches or pull requests

3 participants