Skip to content

getValue() for wxt-dev/storage ignores init() #1980

@ianleck

Description

@ianleck

Describe the bug

Bug:
Init no longer functions correctly after updating from wxt-dev/storage 1.1.1 to the 1.2.6.

For example, if I define an item with:

const example = storage.defineItem<boolean[]>(
  'local:exampleItemArray',
    { init: () => [] }
  );

I start getting 'example' is possibly 'null'.

Expectation:
The init option should also narrow the type to non-null (like fallback does), since it guarantees a value will always exist. This is either a type oversight or a regression in the overload signatures.

Reproduction

const example = storage.defineItem<boolean[]>(
  'local:exampleItemArray',
    { init: () => [] }
  );

Steps to reproduce

Define an item with init instead of fallback.

System Info

System:
    OS: macOS 14.5
    CPU: (8) arm64 Apple M2
    Memory: 250.27 MB / 24.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.17.0 - /Users/ianleck/.nvm/versions/node/v20.17.0/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.8.2 - /Users/ianleck/.nvm/versions/node/v20.17.0/bin/npm
    pnpm: 10.17.0 - /Users/ianleck/.nvm/versions/node/v20.17.0/bin/pnpm
    Deno: 2.1.4 - /Users/ianleck/.deno/bin/deno
  Browsers:
    Brave Browser: 142.1.84.141
    Chrome: 142.0.7444.176
    Firefox: 145.0
    Safari: 17.5
  npmPackages:
    wxt: ^0.20.11 => 0.20.11

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    pending-triageSomeone (usually a maintainer) needs to look into this to see if it's a bug

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions