glint icon indicating copy to clipboard operation
glint copied to clipboard

[feat] improve attributes transform semantics to match hbs AST

Open lifeart opened this issue 1 year ago • 1 comments

Handlebars AST attribute representation: (array of elements)

image

In scope of this PR we matching attributes to hbs semantics, where it's represented as array of key-value pairs, instead of record. It gives us more flexibility in syntaxes and reduce potential fail-cases because attribute name is explicitly string.

And getting rid of An object literal cannot have multiple properties with the same name typescript error.

- export declare function applyAttributes(element: Element, attrs: Record<string, AttrValue>): void;
+ export declare function applyAttributes(element: Element, attrs: Array<[string, AttrValue]>): void;

Resolves: https://github.com/typed-ember/glint/issues/693

Note, we not getting DX worse, because template-lint has rule to warn about duplicated attributes: https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/no-duplicate-attributes.md


Sidenote:

It seems we could have autocomoplete/attibutes validation if replace

export declare function applyAttributes(element: Element, attrs: Array<[string, AttrValue]>): void;

With

export declare function applyAttributes<T extends Element, K extends keyof T>(element: T, attrs: Array<[K, T[K] | SafeString]>): void;
image image

ts playground

lifeart avatar Jan 23 '24 03:01 lifeart

this is also beeing worked on in #663, i mean the attributes autocomoplete/validation

patricklx avatar Jan 29 '24 13:01 patricklx