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

fix: #1005 fixed, by updating type-definations to getItem method. #1007

Merged
merged 7 commits into from
Oct 2, 2024

Conversation

baraich
Copy link
Contributor

@baraich baraich commented Sep 28, 2024

Changes

Updated the getItem function to check if the fallback parameter is provided. If it is, the function will return a non-null type.

Copy link

netlify bot commented Sep 28, 2024

Deploy Preview for creative-fairy-df92c4 ready!

Name Link
🔨 Latest commit 9626fd9
🔍 Latest deploy log https://app.netlify.com/sites/creative-fairy-df92c4/deploys/66fb6d60d6cc3c0008b8de2d
😎 Deploy Preview https://deploy-preview-1007--creative-fairy-df92c4.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@Timeraa
Copy link
Contributor

Timeraa commented Sep 29, 2024

Maybe add a type test into the storage tests for that

@baraich
Copy link
Contributor Author

baraich commented Sep 29, 2024

@Timeraa I am unsure, what do you mean? I have tested the project locally and after then I created a pull request.

Some cases

const value = await storage.getItem("local:key")
      // ^? any 
const value = await storage.getItem<string>("local:key")
      // ^? string | null 
const value = await storage.getItem("local:key", { fallback: "abc" })
      // ^? string 
const value = await storage.getItem<string>("local:key", { fallback: "abc" })
      // ^? string 

@Timeraa
Copy link
Contributor

Timeraa commented Sep 29, 2024

Using https://vitest.dev/guide/testing-types in https://github.com/wxt-dev/wxt/blob/main/packages/wxt/src/__tests__/storage.test.ts

I think @aklinker1 needs to add the --typecheck flag to the test commands but you can use vitest --typecheck in the packages/wxt package

@baraich
Copy link
Contributor Author

baraich commented Sep 29, 2024

Using https://vitest.dev/guide/testing-types in https://github.com/wxt-dev/wxt/blob/main/packages/wxt/src/__tests__/storage.test.ts

I think @aklinker1 needs to add the --typecheck flag to the test commands but you can use vitest --typecheck in the packages/wxt package

@Timeraa Hi, according to your guidance I rank the typecheck command and all the tests in storage.test.ts are passing and I am sure it's safe to merge.
image

@baraich
Copy link
Contributor Author

baraich commented Sep 29, 2024

@aklinker1 or @Timeraa, please merge the pull request asap, I am unable to concentrate on my tomorrows' board examination or if you are not planning to merge please provide appropriate feedback.

Thanks in advance.

@baraich
Copy link
Contributor Author

baraich commented Sep 29, 2024

Also, here is the flow of types.

  • When we haven't provided a type hint, or fallback parameter the return type in unknown.
    image

  • Now, I have given a type hint.
    image

  • And when I have given fallback, then the following behaviour is expected.
    image

  • Moreover, it has type-safety built in, if I hint the function that type is number then I cannot pass anything else than number to fallback parameter.
    image

Copy link

pkg-pr-new bot commented Sep 30, 2024

Open in Stackblitz

@wxt-dev/auto-icons

pnpm add https://pkg.pr.new/@wxt-dev/auto-icons@1007

@wxt-dev/i18n

pnpm add https://pkg.pr.new/@wxt-dev/i18n@1007

@wxt-dev/module-react

pnpm add https://pkg.pr.new/@wxt-dev/module-react@1007

@wxt-dev/module-solid

pnpm add https://pkg.pr.new/@wxt-dev/module-solid@1007

@wxt-dev/module-svelte

pnpm add https://pkg.pr.new/@wxt-dev/module-svelte@1007

@wxt-dev/module-vue

pnpm add https://pkg.pr.new/@wxt-dev/module-vue@1007

wxt

pnpm add https://pkg.pr.new/wxt@1007

commit: 9626fd9

Copy link

codecov bot commented Sep 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.87%. Comparing base (a64ff22) to head (9626fd9).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1007      +/-   ##
==========================================
- Coverage   82.14%   81.87%   -0.28%     
==========================================
  Files         127      127              
  Lines        6625     6625              
  Branches     1103     1102       -1     
==========================================
- Hits         5442     5424      -18     
- Misses       1169     1187      +18     
  Partials       14       14              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@aklinker1 aklinker1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make the PR editable by maintainers? I can't seem to push the type tests.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork

    it('should return a nullable type when getItem is called without a fallback', async () => {
      const res = await storage.getItem<string>('local:test');
      expectTypeOf(res).toBeNullable();
    });

    it('should return a nullable type when getItem is called without a fallback', async () => {
      const res = await storage.getItem<string>('local:test', {
        fallback: 'test',
      });
      expectTypeOf(res).not.toBeNullable();
    });

@baraich
Copy link
Contributor Author

baraich commented Sep 30, 2024

@aklinker1 Hi, I have allowed edits by maintainers.

@baraich
Copy link
Contributor Author

baraich commented Sep 30, 2024

@aklinker1 Hi, I think there is some problem with your test code.
image

@aklinker1
Copy link
Collaborator

aklinker1 commented Sep 30, 2024

No, the test code is correct, your change doesn't work when the first type parameter is passed in.

-     const res = await storage.getItem<string>('local:test', {
+     const res = await storage.getItem('local:test', {
        fallback: 'test',
      });

@baraich
Copy link
Contributor Author

baraich commented Sep 30, 2024

@aklinker1, Yes, you are write, when we pass the type hint and fallback. It defaults to typehint and null condition. Will fix an update. Thanks

@baraich
Copy link
Contributor Author

baraich commented Oct 1, 2024

@aklinker1 All 16 tests are passing now.

@baraich
Copy link
Contributor Author

baraich commented Oct 1, 2024

@aklinker1 Why is it should changes required, I have made the changes please review them. Your reviewing part is left. Thanks.

Copy link
Collaborator

@aklinker1 aklinker1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@baraich
Copy link
Contributor Author

baraich commented Oct 2, 2024

Thanks, for approving the changes. As this is my first time contribution to open source, I am not aware of the steps involved. Are there more steps to this, as the pull request doesn't seem as it has been merged (please correct if wrong) even after you have approved.

@aklinker1
Copy link
Collaborator

Just had to wait for checks to pass, just getting back to this now!

@aklinker1 aklinker1 merged commit 5faa5d7 into wxt-dev:main Oct 2, 2024
18 checks passed
@aklinker1
Copy link
Collaborator

Released in v0.19.11

@baraich baraich deleted the fixes-#1005 branch October 3, 2024 09:24
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

Successfully merging this pull request may close these issues.

4 participants