[docs] Fix 'property' has no initializer issue in TypeScript property samples #1274
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: #1273
Context
When looking at our documentation, the very first TypeScript example shows: https://lit.dev/docs/components/properties/
This results in a TypeScript error:
Property 'name' has no initializer and is not definitely assigned in the constructor.
.This can be globally resolved by relaxing the TypeScript compiler via
"strictPropertyInitialization": false
, but we should prefer documentation that is as explicit/strict as possible.We have an example in the playground where it makes sense to not initialize a property. So I've added that syntax to our
properties.md
docs.Fix:
This clearly states that the property should be a string, but it can also be undefined if no-one initialized it.
Risk & Tests
This is a low risk content only change – tested by checking out preview URL.