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
Improve types for (un)compiled template results #4309
Conversation
🦋 Changeset detectedLatest commit: d4291a2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📊 Tachometer Benchmark ResultsSummarynop-update
render
update
update-reflect
Resultsthis-change
render
update
update-reflect
this-change, tip-of-tree, previous-release
render
update
nop-update
this-change, tip-of-tree, previous-release
render
update
this-change, tip-of-tree, previous-release
render
update
update-reflect
|
The size of lit-html.js and lit-core.min.js are as expected. |
c94a54f
to
51abba4
Compare
packages/lit-html/src/lit-html.ts
Outdated
* In Lit 4, this type will be an alias of | ||
* MaybeCompiledTemplateResult, so that code will get type errors if it assumes | ||
* that Lit templates are not compiled. When deliberately working with only | ||
* one, use either CompiledTemplateResult or UncompiledTemplateResult |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Could make CompiledTemplateResult
and UncompiledTemplateResult
use @linkcode
so they link to the respective docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice!
// This property needs to remain unminified. | ||
['_$litType$']: T; | ||
strings: TemplateStringsArray; | ||
values: unknown[]; | ||
}; | ||
|
||
export type MaybeCompiledTemplateResult<T extends ResultType = ResultType> = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This could use a JSDoc to clarify why this is used. Probably want to call out that this should ideally be the type of html
or svg
when you're trying to target both uncompiled and compiled environments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! Done
Adds two new types: `UncompiledTemplateResult` and `MaybeCompiledTemplateResult`. Currently `UncompiledTemplateResult` is the same as `TemplateResult`, and `MaybeCompiledTemplateResult` is the union of the compiled and uncompiled types. We'd like for code to be able to handle the `html` and `svg` functions returning a MaybeCompiledTemplateResult. Changing that type will be a major breaking change though, and we don't want to do a major version so quickly, but this lays the ground work, and provides future-compatible types that people can use when they want to be explicit about which type they mean, because while TemplateResult will change, MaybeCompiled, Uncompiled, and Compiled will all have the same meanings in the next major version.
51abba4
to
d4291a2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Adds two new types:
UncompiledTemplateResult
andMaybeCompiledTemplateResult
. CurrentlyUncompiledTemplateResult
is the same asTemplateResult
, andMaybeCompiledTemplateResult
is the union of the compiled and uncompiled types.We'd like for code to be able to handle the
html
andsvg
functions returning a MaybeCompiledTemplateResult. Changing that type will be a major breaking change though, and we don't want to do a major version so quickly, but this lays the ground work, and provides future-compatible types that people can use when they want to be explicit about which type they mean, because while TemplateResult will change, MaybeCompiled, Uncompiled, and Compiled will all have the same meanings in the next major version.