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

Typescript: Second argument to readable should be optional #6345

Closed
utherpally opened this issue May 20, 2021 · 1 comment · Fixed by #6293
Closed

Typescript: Second argument to readable should be optional #6345

utherpally opened this issue May 20, 2021 · 1 comment · Fixed by #6293

Comments

@utherpally
Copy link

Describe the bug
I think creating a store without a start/stop notifier is totally valid for some special use cases (e.g. SSR friendly).

I write a lot of things like this in my SvelteKit(svelte@3.38.2) app to make Typescript checker happy:

function noop() {}

export const useMedia = (query: string) => {
  if(!browser) {
    return readable(false, noop); // 1
  }
  // Do something real here
}

export const useWindowSize = ({initialWidth = Infinity, initialHeight = Infinity}) => {
  if(!browser) {
    return {
      width: readable(initialWidth, noop), // 2
      height: readable(initialHeight, noop), // 3
    }; 
  }
  // Do something real here
}

Expected behavior
store = readable(neverChangedValue) etc should be accepted by TypeScript.

Sorry for my bad English

dummdidumm pushed a commit that referenced this issue May 20, 2021
Fixes #6291
Fixes #6345

Both writable and readable initialized without any arguments are already valid, but TS complains about it. This makes both allowed to be emptily initialized. It's also possible to invoke readable with one argument only.
@Conduitry
Copy link
Member

These types have been updated in 3.38.3.

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

Successfully merging a pull request may close this issue.

3 participants