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

Type definitions for setContext #103

Open
flekschas opened this issue Nov 14, 2022 · 0 comments
Open

Type definitions for setContext #103

flekschas opened this issue Nov 14, 2022 · 0 comments

Comments

@flekschas
Copy link

I am wondering if it's possible to annotate setContext calls such that the exposed variables are typed.

For example:

<!-- MyLogger.svelte -->
<script context="module">
  import { setContext } from 'svelte';
  /**
   * Log something
   * @type {(message: string) => void}
   */
  function log(message) {
    console.log(message);
  }

  setContext('my-logger', log);
</script>

My problem is that even though log has type annotations, when someone gets the function via getContext('my-logger') the type is unknown.

I wonder if there's a way to add type annotations to setContext.

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

1 participant