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

Component refs and exported properties #330

Closed
dkzlv opened this issue Jul 22, 2020 · 1 comment
Closed

Component refs and exported properties #330

dkzlv opened this issue Jul 22, 2020 · 1 comment

Comments

@dkzlv
Copy link

dkzlv commented Jul 22, 2020

Is your feature request related to a problem? Please describe.
I am not really sure if it is a feature request, bug report or request for docs.

Svelte allows you to use exported const properties when using component refs.

Child.svelte:

<script lang="ts">
  export const get = () => 'hey';
</script>

Parent.svelte:

<script lang="ts">
  import Child from './Child.svelte';

  let childRef: Child | undefined = undefined;
  
  // Error: `Property 'get' does not exist on type 'Child__SvelteComponent_'.` when calling the function
  const call = () => childRef!.get();
</script>

<Child bind:this={childRef} />

Describe the solution you'd like
It would be cool if the compiler knew the signatures of exported properties automatically.

Describe alternatives you've considered
I see two alternatives, both of which drop the typing security drastically:

  1. use any for refs
  2. assign the type explicitly
let childRef: Child & { get: () => string }

It's bad, because when child changes its signature parent would never know about it until we manually update the signature.

@dummdidumm
Copy link
Member

Duplicate of #307

@dummdidumm dummdidumm marked this as a duplicate of #307 Jul 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants