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

[Bug] Properties of MutableArray "does not exist" on tracked array after importing from 'ember-source/types/preview' #20463

Closed
johanrd opened this issue May 26, 2023 · 4 comments

Comments

@johanrd
Copy link
Contributor

johanrd commented May 26, 2023

🐞 Describe the Bug

Importing types from ember-source/types/preview breaks types of MutableArray properties on tracked arrays.

🔬 Minimal Reproduction

Clone this repo: https://github.com/johanrd/ember-typescript-reproducible-mutable-array

😕 Actual Behavior

Open app.ts, and see typescript error 2339 on line 18: this.list.pushObject(object):

Property 'pushObject' does not exist on type '{}[]'.ts(2339)

This also happens for other properties of MutableArray, e.g. firstObject, yet all other other type imports from ember-source works well, as far as I can see.

🤔 Expected Behavior

Types of MutableArray to be imported correctly – as they are from the "old" @types/ember__array package. Test that the 'old way' runs well in the same environment by simply removing the type imports on line 8:

-import 'ember-source/types/preview';

^ no errors after removing this line

🌍 Environment

  • Ember: 4.12.0 and 5.1.0-beta1
@boris-petrov
Copy link
Contributor

Note that this will fail at runtime unless Array's prototype-extensions are enabled (which you shouldn't do) - so the error is correct - there is no such method on a native JS array.

@johanrd
Copy link
Contributor Author

johanrd commented May 30, 2023

Hi @boris-petrov, thanks for your reply.

For me, Array's prototype-extensions seems to be enabled, which also seems to be the default in ember, according to the docs:

By default, Ember.js will extend the prototypes of native JavaScript arrays to implement the Ember.Enumerable, Ember.MutableEnumerable, Ember.MutableArray and Ember.Array interfaces. This polyfills ECMAScript 5 array methods in browsers that do not implement them, adds convenience methods and properties to built-in arrays, and makes array mutations observable.

There are no errors at runtime in the browser, only at compile time from typescript.

@boris-petrov
Copy link
Contributor

Interesting! I guess the documentation hasn't been updated. As they have been disabled by default for a while now.

@johanrd
Copy link
Contributor Author

johanrd commented May 30, 2023

Ok, thanks, closing in favor of #20465

@johanrd johanrd closed this as completed May 30, 2023
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

2 participants