Skip to content

Commit

Permalink
update jsdoc comment
Browse files Browse the repository at this point in the history
  • Loading branch information
trusktr committed Sep 20, 2024
1 parent e474ad0 commit c372a81
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
11 changes: 9 additions & 2 deletions dist/LumeElement.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,21 @@ type Template = TemplateContent | (() => TemplateContent);
* }
* ```
*
* The result is that TypeScript will properly type-check the following
* JSX expression (notice lorem-ipsum is dash-case):
* The result is that TypeScript will properly type-check the following JSX
* expression (notice loremIpsum is camelCase in the class, but dash-cased
* lorem-ipsum is used in the JSX):
*
* ```jsx
* let coolEl = <cool-element foo={'foo'} bar={null} lorem-ipsum={456}></cool-element>
* ```
*/
export type ElementAttributes<ElementType, SelectedProperties extends keyof ElementType, AdditionalProperties extends object = {}> = WithStringValues<DashCasedProps<Partial<Pick<ElementType, SelectedProperties>>>> & AdditionalProperties & Omit<JSX.HTMLAttributes<ElementType>, SelectedProperties | keyof AdditionalProperties>;
/**
* Make all non-string properties union with |string because they can all
* receive string values from string attributes like opacity="0.5" (those values
* are converted to the types of values they should be, f.e. reading a
* `@numberAttribute` property always returns a `number`)
*/
type WithStringValues<Type extends object> = {
[Property in keyof Type]: NonNullable<Type[Property]> extends string ? Type[Property] : Type[Property] | string;
};
Expand Down
2 changes: 1 addition & 1 deletion dist/LumeElement.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions src/LumeElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,9 @@ type Template = TemplateContent | (() => TemplateContent)
* }
* ```
*
* The result is that TypeScript will properly type-check the following
* JSX expression (notice lorem-ipsum is dash-case):
* The result is that TypeScript will properly type-check the following JSX
* expression (notice loremIpsum is camelCase in the class, but dash-cased
* lorem-ipsum is used in the JSX):
*
* ```jsx
* let coolEl = <cool-element foo={'foo'} bar={null} lorem-ipsum={456}></cool-element>
Expand All @@ -497,6 +498,12 @@ export type ElementAttributes<
AdditionalProperties &
Omit<JSX.HTMLAttributes<ElementType>, SelectedProperties | keyof AdditionalProperties>

/**
* Make all non-string properties union with |string because they can all
* receive string values from string attributes like opacity="0.5" (those values
* are converted to the types of values they should be, f.e. reading a
* `@numberAttribute` property always returns a `number`)
*/
type WithStringValues<Type extends object> = {
[Property in keyof Type]: NonNullable<Type[Property]> extends string ? Type[Property] : Type[Property] | string
}

0 comments on commit c372a81

Please sign in to comment.