Skip to content
Discussion options

You must be logged in to vote

The key is ReturnType.

Full answer with example by H.B. - https://stackoverflow.com/a/73543650/2908501


There are two primary options: Use preprocess-svelte and write TypeScript or add JSDoc type annotations.

With TS:

<script lang="ts">
    import { getContext } from 'svelte';

    // Prop
    export let count: StoreType;

    // Context
    const store = getContext<StoreType>('context');
</script>

With JSDoc:

<script>
    import { getContext } from 'svelte';

    // Prop
    /** @type {StoreType} */
    export let count;

    // Context
    /** @type {StoreType} */
    const store = getContext('context');
</script>

You can declare types in separate .d.ts files or use @typedef.

The create…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by lukaszpolowczyk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant