-
-
Notifications
You must be signed in to change notification settings - Fork 397
fix: fix typescript error on defineItem
fallback
#1601
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
Conversation
✅ Deploy Preview for creative-fairy-df92c4 ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, looks good!
Could you add type tests to packages/storage/src/__tests__/index.test.ts
instead of just listing them in the PR description? That way we can ensure they don't break in the future.
Something like this should be good enough:
it("should consider the fallback when typing the value", () => {
expectTypeOf(...).toBe<...>()
});
Don't worry about running vitest's type-test mode, just run pnpm check
to run the typescript compiler.
@aklinker1 Thanks for the review! Tests are added for this case and passing with |
@wxt-dev/analytics
@wxt-dev/auto-icons
@wxt-dev/browser
@wxt-dev/i18n
@wxt-dev/module-react
@wxt-dev/module-solid
@wxt-dev/module-svelte
@wxt-dev/module-vue
@wxt-dev/storage
@wxt-dev/unocss
@wxt-dev/webextension-polyfill
wxt
commit: |
Thanks for helping make WXT better! |
wxt-dev#1601 adjusted the typing of `defineItem` to examine whether `defaultValue` or `fallback` were passed, and only then, remove the `null` from the possible returned value. However, it did not accommodate the case where an `init` function is passed to prevent a `null` return, which was previously allowed. Add a new type signature for this case, and add some tests for type expectations to catch the issue.
wxt-dev#1601 adjusted the typing of `defineItem` to examine whether `defaultValue` or `fallback` were passed, and only then, remove the `null` from the possible returned value. However, it did not accommodate the case where an `init` function is passed to prevent a `null` return, which was previously allowed. Add a new type signature for this case, and add some tests for type expectations to catch the issue.
Overview
Currently, the second signature of
WxtStorage.defineItem
method is incorrect that it doesn't respect the fallback value.wxt/packages/storage/src/index.ts
Lines 748 to 754 in 4c35798
The following examples show the bug clearly.
Manual Testing
Related Issue