Skip to content

Clarify difference between initial value and default value in Svelte tutorial #9078

@kenbanks-peng

Description

@kenbanks-peng

Describe the bug

Appreciating the decision to stick with legacy behavior for "initial value" syntax:

export let myProp = "initialValue";

versus true default value syntax:

export let myProp;
$: myProp ??= 'defaultValue';

Could the distinction be made clearer in the Svelte tutorial for default values as it currently teaches that a default value is achieved using the "initial value" syntax?

This difference explains why my TS typing was always complaining that it could not execute functions that were optional props since they could be undefined. And here I am thinking, but they are not undefined since I gave them default values. But typescript knew that those initial values could be over-written back to undefined!!! So now I have to go update all my code.

Reproduction

export let myProp = "initialValue";

Logs

No response

System Info

System:
    OS: macOS 13.3.1
    CPU: (8) arm64 Apple M2
    Memory: 34.16 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.17.0 - ~/Library/pnpm/nodejs_current/bin/node
    npm: 9.6.7 - ~/Library/pnpm/npm
    pnpm: 8.6.6 - ~/Library/pnpm/pnpm
  Browsers:
    Chrome: 115.0.5790.170
    Safari: 16.4
  npmPackages:
    svelte: ^4.1.2 => 4.1.2

Severity

annoyance

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