fix(writer)!: use type alias instead of interface for RestProps
#138
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #137
Currently, Sveld creates an Interface type for component props. If the component has
RestProps
, the interface will extend it. For most cases, this works fine.However, this can cause a TypeScript error if component props incorrectly extends
RestProps
.A very simple example:
A TypeScript error occurs because the
tabindex
on the ComponentProps incorrectly extends that onSvelteHTMLElements["a"]
(tabindex
can bestring | number
).The correct approach would be to use a type alias for the generated component props type.
Note, however, that the below example will result in a TypeScript error for the consumer. This is because
tabindex
already exists onSvelteHTMLElements["a"]
and incorrectly extends the type (string | number
vs.string
).The last step is to omit the keys from the component props from
RestProps
.In summary:
RestProps
can be an intersection of multipleSvelteHTMLElements
.RestProps
and$Props
where keys from$Props
are omitted fromRestProps
.This is considered a breaking change since the generated component type is exported from the type file.