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

{{#each-in}} breaks if used with a Map #645

Open
jelhan opened this issue Nov 4, 2023 · 4 comments
Open

{{#each-in}} breaks if used with a Map #645

jelhan opened this issue Nov 4, 2023 · 4 comments

Comments

@jelhan
Copy link

jelhan commented Nov 4, 2023

The value of {{#each-in}} has an unexpected type if being used with a Map. Even trying to render the value in the template throws an error.

Simple reproduction:

import Component from '@glimmer/component';

export default class PlaygroundComponent extends Component {
  map: Map<string, number> = new Map([
    ['a', 1],
    ['b', 2],
    ['c', 3],
  ]);
{{#each-in this.map as |key value|}}
  {{key}}
  {{value}}
{{/each-in}}
app/components/playground.hbs:3:3 - error TS2345: Only primitive values and certain DOM objects (see `ContentValue` in `@glint/template`) are usable as top-level template content.
  Argument of type 'number | ((callbackfn: (value: number, key: string, map: Map<string, number>) => void, thisArg?: any) => void) | (() => IterableIterator<[string, number]>) | ... 6 more ... | ((key: string) => boolean)' is not assignable to parameter of type 'ContentValue'.
    Type '(callbackfn: (value: number, key: string, map: Map<string, number>) => void, thisArg?: any) => void' is not assignable to type 'ContentValue'.

3   {{value}}
    ~~~~~~~~~

Please note that it is working fine if using a POJO instead of a Map.

typescript: 5.2.2
@glint/template: 1.2.1

@dfreeman
Copy link
Member

dfreeman commented Nov 4, 2023

Neither the Guides nor the API docs suggest that each-in handles Maps specially, from what I can see. Can you point to documentation for that?

@NullVoxPopuli
Copy link
Contributor

The guides and api docs are underspecified.

It makes sense that you'd want to allow all iterables, and each/each-in do work with all iterables

@jelhan
Copy link
Author

jelhan commented Nov 4, 2023

Neither the Guides nor the API docs suggest that each-in handles Maps specially, from what I can see. Can you point to documentation for that?

Support was added in Ember 3.2.0. It was considered a bug fix. Please find details in the changelog: https://github.com/emberjs/ember.js/blob/main/CHANGELOG.md#v320-may-31-2018

@dfreeman
Copy link
Member

dfreeman commented Nov 4, 2023

In that case a PR to account for the behavior would be welcome

The guides and api docs are underspecified

Given that the guides talk about each-in by way of comparison to Object.keys and for...in loops, both of which are not iterable-aware, I'd say they're more than underspecified and rather actively misleading.

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