Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Improve TypeScript type definition for stores #1556

Closed
albertms10 opened this issue Sep 24, 2020 · 3 comments · Fixed by #1601
Closed

Improve TypeScript type definition for stores #1556

albertms10 opened this issue Sep 24, 2020 · 3 comments · Fixed by #1601

Comments

@albertms10
Copy link

albertms10 commented Sep 24, 2020

Is your feature request related to a problem? Please describe.
The stores function from @sapper/app has an unknown return type, although there is a known object returning some predefined values such as preloading, page, session, as seen in the Sapper Docs.

<script>
  import { stores } from '@sapper/app';
  const { preloading, page, session } = stores(); // => `unknown`, destructured items are `any`

  const delayedPreloading = derived(
    preloading,
    (currentPreloading, set) => { // as preloading is treated as `any`, TypeScript cannot infer types for fn parameters
      // ...
    }
  );

  // ...
</script>

Describe the solution you'd like
Adding types for these stores would improve DX.

Describe alternatives you've considered
Just ignore TypeScript warning about the any type in use cases.

@dummdidumm dummdidumm transferred this issue from sveltejs/language-tools Sep 24, 2020
@benmccann
Copy link
Member

This is defined here:

export const stores: () => unknown;

@benmccann benmccann changed the title Sapper: support for default stores type Improve TypeScript type definition for stores Sep 24, 2020
@TheComputerM
Copy link
Contributor

Can I try to fix this issue and open a PR?

@albertms10
Copy link
Author

Of course!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants