-
-
Notifications
You must be signed in to change notification settings - Fork 205
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
[TypeScript] cannot specify param type on arrow functions passed as parameters from markup #312
Comments
This is the expected behavior for now. About the typescript error, we don't know the type of the event. When it's a forwarded native event it won't have the Second, because the svelte preprocess API constrains, typescript in the template is not supported now. |
I think it is worth having detail? available on the event. We should update the JSX event types to have detail?: unknown so that CustomEvent typed handlers will work |
I am trying to type-check the forwarded DOM event in #303. Once it's possible, all unknow event can be changed to |
+1 for adding a detail? in the meantime and I hope that ts in markup could be solved in the near future, it feels like a gap in ts support. I think that at least it should be clearly documented when we officially launch ts support. (I would consider addign the I had several handlers of the form
Basically moving the cast our of the markup. Perhaps, for the time being, we could add some recipes for working with ts codebases... Note: I just saw you've already commited a temporary fix (WOW, that is REALLY fast! congrats). How can I try it? I guess svelte2tsc is used by svelte preprocess, right? |
Typescript in the template is an upstream problem. Tracked here sveltejs/svelte#4701. I don't think it is coming soon. |
No, svelte2tsx is used in the IDE level not build. |
The fact that you cannot use typescript inside template/markup is documented here |
@dummdidumm thanks a lot! somehow I missed this page, it's got really useful tips |
Fixed through #303 |
Describe the bug
cannot specify param type on arrow functions passed as parameters
e.g.:
gives the following ts warning:
If I try to specify e to be a CustomEvent like this:
gives the following ts error:
Also tried with
and
both returning
On the other hand, this works ok:
To Reproduce
create a ts svelte project with:
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
System (please complete the following information):
svelte-language-server
,svelte-check
, orsvelte2tsx
if you use one of the npm packages directly] (not sure which one)Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: