Skip to content
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

Action parameter type error #754

Closed
pushkine opened this issue Jan 11, 2021 · 4 comments
Closed

Action parameter type error #754

pushkine opened this issue Jan 11, 2021 · 4 comments
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.

Comments

@pushkine
Copy link
Contributor

pushkine commented Jan 11, 2021

<script lang="ts">
	function action<P extends Partial<{ border: "left" | "right" }>>(_, props: P) {}
	action(null, { border: "right" });
</script>

<div use:action={{ border: 'right' }} />

use:action throws Type 'string' is not assignable to type '"left" | "right"'. ts(2345)
Expected no error, as calling the action in the script block does not throw
{ border: 'right' as const } throws Unexpected token ts(-1)

@pushkine pushkine added the bug Something isn't working label Jan 11, 2021
@dummdidumm
Copy link
Member

I am not able to reproduce this.

@pushkine
Copy link
Contributor Author

Code_2021-01-16_02-25-35

I get it in a blank file without any tsconfig, not sure what to say

@jasonlyu123
Copy link
Member

jasonlyu123 commented Jan 16, 2021

I can reproduce it. My guess is that the type parameter of the __sveltets_ensureAction is inferred from the action parameter instead of the type parameter of the action. Thus the error is on the action instead of parameter.

We might need to find another way to transform the action in svelte2tsx.

@dummdidumm
Copy link
Member

dummdidumm commented Jan 16, 2021

The "no tsconfig.json" was the key, now I can reproduce it, too. Have another transformation lying around somewhere, need to look it up and see if it solves the issue.

dummdidumm pushed a commit to dummdidumm/language-tools that referenced this issue Jan 17, 2021
sveltejs#754
Avoid incorrect type inference in edge cases by calling the functions directly.
Also cleaned up typings - actions/animations/transitions only have one parameter, not arbitrary ones. Therefore passing a ( and ) around the params so they are interpreted as a comma-separated command instead of two parameters if user does use:action={1,2} , because it is interpreted as action(node, (1,2)) by the Svelte compiler.
dummdidumm added a commit that referenced this issue Jan 17, 2021
#754
Avoid incorrect type inference in edge cases by calling the functions directly.
Also cleaned up typings - actions/animations/transitions only have one parameter, not arbitrary ones. Therefore passing a ( and ) around the params so they are interpreted as a comma-separated command instead of two parameters if user does use:action={1,2} , because it is interpreted as action(node, (1,2)) by the Svelte compiler.
@dummdidumm dummdidumm added the Fixed Fixed in master branch. Pending production release. label Jan 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Fixed Fixed in master branch. Pending production release.
Projects
None yet
Development

No branches or pull requests

3 participants