ember.js: [Bug] Computed property smashing regression on 3.21.3

🐞 Describe the Bug

In an app using ember-cli-typescript, a controller can declare the type of its model like this:

export default class Application extends Controller {
  model: Whatever;
}

This works fine in 3.21.2. But using ember-source 3.21.3, it causes this.model to be undefined.

🔬 Minimal Reproduction

Run this app and see it crash: https://github.com/ef4/--bug-repro

Switch the app to use ember-source 3.21.2 and see it not crash.

Or comment out the type declaration for model in app/controllers/application.ts and see it not crash.

😕 Actual Behavior

The model computed property appears to be getting smashed by typescript’s compiler output (which emits something like Object.defineProperty(this, 'model', void 0) in the constructor).

🤔 Expected Behavior

Should behave the same as in ember 3.21.2.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 25 (25 by maintainers)

Most upvoted comments

This was fixed in #19197 and included in 3.22.1.

You should! That’s the correct way to define a type with these class field semantics (that is, defined by an external-to-the-class caller). We used and recommended the other approach because it’s all we had, but the declare syntax was designed to handle exactly the Ember scenario (ours was not the only use case but was definitely part of the input to the design process for TS).

@ef4 I’m not sure what changed here exactly, but I believe TypeScript users should be using declare model: Whatever; at this point, because in the future that will always clobber, and there’s not really a way around that (except redefining the property after the class has been instantiated)