Skip to content

Typescript: Second argument to readable should be optional #6345

Closed
@utherpally

Description

@utherpally

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions