Skip to content

lit-plugin(no-complex-attribute-binding) when property has a converter #123

@bennypowers

Description

@bennypowers

Hello!

My intended API is

// either
html`<trigger-mutation refetch-queries="OneQuery,AnotherQuery"></trigger-mutation>`
// or
html`<trigger-mutation .refetchQueries="${['OneQuery', 'AnotherQuery']}"></trigger-mutation>`

As such, I've defined refetchQueries as:

class TriggerMutation extends ApolloMutation {
  @property({ attribute: 'refetch-queries', converter: {
    fromAttribute(string: string): string[] {
      return !string ? undefined : string.split(',').map(x => x.trim()).filter(Boolean);
    },
    toAttribute(value: string[]): string {
      return Array.isArray(value) ? value.join(',') : null;
    },
  } })
  refetchQueries: string[];
}

Only to get this error:

You are assigning the primitive '"OneQuery,AnotherQuery"' to a non-primitive type 'string[]'. Use '.' binding instead?lit-plugin(no-complex-attribute-binding)(2)

As converter is intended to cast strings, perhaps this rule should be amended to allow ignoring properties with a converter or with type: Array or type: Object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions