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: wrapping an optional value inside a store makes it non-optional #12502

Open
kevinrenskers opened this issue Jul 19, 2024 · 0 comments

Comments

@kevinrenskers
Copy link

Describe the bug

When I wrap an optional value in a writable store, it becomes non-optional.

Reproduction

These 2 lines are all you need:

let value: string | undefined;
let store = writable(value);

The type of store is Writable<string>.

I can work around it by manually specifying the type:

let store = writable<string | undefined>(value);

But it's weird that this is necessary.

Logs

No response

System Info

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Max
    Memory: 48.22 MB / 32.00 GB
    Shell: 3.7.1 - /opt/homebrew/bin/fish
  Binaries:
    Node: 18.17.1 - ~/Library/pnpm/node
    npm: 9.6.7 - ~/Library/pnpm/npm
    pnpm: 8.15.3 - ~/Library/pnpm/pnpm
  Browsers:
    Safari: 17.5
  npmPackages:
    svelte: ^4.2.18 => 4.2.18

Severity

annoyance

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