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.
#2444 #2417 #2425 #2385 (comment)
The snippet is now transformed into a function with the return type so that The default parameter type can be inferred:
Another solution I considered using is an IIFE function so the inferred type is still
Snippet<[...]>
. But seems like typescript almost always expanded the type in hover. AndI went for the
ReturnType
because the hover is shorter and the code generation is slightly simpler but OK with both so I could also change it to IIFE.Breaking change
Since it is now possible to type snippets with JSDoc I removed explicit
any
in the generated code while changing the generation. This is a breaking change for js components with type-check but we can also add theany
back for parameter without a default.Scoping issues
The
var
is changed toconst
because this result in a runtime error but Typescript give a green light if it's var.The generated const is now hoist to before the first non-snippet sibling for #2417. And for implicit props, it's still passed directly to the component so the type can be inferred but another variable is generated for #2425
A limitation is that we'll have to map the definition/reference/rename back but we can probably do this in a separate issue. Not even sure if many people actually rewrite something like this.