Skip to content

Reactive collections should type arguments as immutable #21074

@bendemboski

Description

@bendemboski

🐞 Describe the Bug

The utilities for creating tracked collections that are exported from @ember/reactive/collections are documented to treat their arguments as immutable, but are typed to only accept mutable arguments. For example, the following produces a type error:

interface FooSignature {
  Args: {
    items: readonly string[];
    setItems: (items: readonly string[]) => void;
  }
}

export default <template>
  {{#let (trackedArray @items) as |arr|}}
    {{!-- etc --}}
  {{/let}}
</template> satisfies TOC<FooSignature>

because @items is a readonly string[] and trackedArray is typed to accept T[], not readonly T[]. The various other utilities have similarly mutable-typed arguments.

🔬 Minimal Reproduction

See above

😕 Actual Behavior

Type error -- unable to pass immutable collections to the reactive utilities

🤔 Expected Behavior

No type error -- should be able to pass immutable collections to the reactive utilities

🌍 Environment

  • Ember: -6.8
  • Ember-CLI: N/A
  • Node.js/npm: N/A
  • OS: N/A
  • Browser: N/a

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions