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

[greasemonkey]: add generics to GM.getValue(string) overload to avoid breaking change at 4.0.4 #62262

Closed
wants to merge 3 commits into from

Conversation

trim21
Copy link
Contributor

@trim21 trim21 commented Sep 14, 2022

Please fill in this template.

Select one of these and delete the others:

If changing an existing definition:

  • Provide a URL to documentation or source code which provides context for the suggested changes: <>
  • If this PR brings the type definitions up to date with a new version of the JS library, update the version number in the header.

Neither, this fix a breaking change added at 4.0.4

previous PR #61907 says due to no-unnecessary-generics rule that GM.getValue without default value should be GM.getValue(name: string): Promise<GM.Value | undefined>, but this will break old working code:

  type Type = 'enum 1' | 'enum 2' | 'enum 3' | ...;
  let v: Type | undefined = await GM.getValue<Type>(key);
  if (!v) {
    init_or_set_v_value()
  }

it raise Type 'Value | undefined' is not assignable to type 'Type | undefined'.   Type 'string' is not assignable to type 'Type | undefined'.

or

  let v = await GM.getValue<Type>(key);

raise error TS2554: Expected 2 arguments, but got 1.

User can call it like GM.getValue(key) as Type | undefined but it still a breaking change when upgrading @types/greasemonkey from 4.0.3 to 4.0.4.

@typescript-bot
Copy link
Contributor

typescript-bot commented Sep 14, 2022

@trim21 Thank you for submitting this PR!

This is a live comment which I will keep updated.

1 package in this PR

Code Reviews

Because you edited one package and updated the tests (👏), I can help you merge this PR once someone else signs off on it.

You can test the changes of this PR in the Playground.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • 🕐 Most recent commit is approved by type definition owners, DT maintainers or others

Once every item on this list is checked, I'll ask you for permission to merge and publish the changes.

Inactive

This PR has been inactive for 11 days — please try to get reviewers!


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 62262,
  "author": "trim21",
  "headCommitOid": "2d91790c03f056d9b1b4626d3e7e73c84cdf7b8d",
  "mergeBaseOid": "fcf20cf13fc35b699d9e5be2bc9c91bcc13f7952",
  "lastPushDate": "2022-09-14T20:26:39.000Z",
  "lastActivityDate": "2022-09-26T06:32:07.000Z",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Well-liked by everyone",
  "pkgInfo": [
    {
      "name": "greasemonkey",
      "kind": "edit",
      "files": [
        {
          "path": "types/greasemonkey/greasemonkey-tests.ts",
          "kind": "test"
        },
        {
          "path": "types/greasemonkey/index.d.ts",
          "kind": "definition"
        }
      ],
      "owners": [
        "kotas",
        "nikolay-borzov"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Well-liked by everyone"
    }
  ],
  "reviews": [],
  "mainBotCommentID": 1247246566,
  "ciResult": "pass"
}

@typescript-bot
Copy link
Contributor

🔔 @kotas @nikolay-borzov — please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

@typescript-bot typescript-bot added the The CI failed When GH Actions fails label Sep 14, 2022
@typescript-bot
Copy link
Contributor

@trim21 The CI build failed! Please review the logs for more information.

Once you've pushed the fixes, the build will automatically re-run. Thanks!

Note: builds which are failing do not end up on the list of PRs for the DT maintainers to review.

@typescript-bot typescript-bot removed the The CI failed When GH Actions fails label Sep 14, 2022
@trim21 trim21 changed the title [greasemonkey]: add generic return value to GM.getValue without default value calling [greasemonkey]: add generic return value to GM.getValue without default value calling to avoid breaking change at 4.0.4 Sep 14, 2022
@trim21 trim21 changed the title [greasemonkey]: add generic return value to GM.getValue without default value calling to avoid breaking change at 4.0.4 [greasemonkey]: add generics to GM.getValue(string) overload to avoid breaking change at 4.0.4 Sep 14, 2022
@nikolay-borzov
Copy link
Contributor

Sorry for bringing breaking changes. But what's stopping you from updating you code?
I believe 4.0.4 update improves types definitions. Using generic for casting types is wrong.

@trim21
Copy link
Contributor Author

trim21 commented Sep 22, 2022

Sorry for bringing breaking changes. But what's stopping you from updating you code? I believe 4.0.4 update improves types definitions. Using generic for casting types is wrong.

Nothing, this PR just prevent breaking change.

And in fact, the other overload getValue<TValue = GM.Value>(name: string, defaultValue: TValue): Promise<TValue> is still using generic as return value type casting for real return type Promise<GM.Value | TValue>.

@typescript-bot
Copy link
Contributor

Re-ping @kotas, @nikolay-borzov:

This PR has been out for over a week, yet I haven't seen any reviews.

Could someone please give it some attention? Thanks!

@typescript-bot typescript-bot added the Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. label Sep 26, 2022
@nikolay-borzov
Copy link
Contributor

I fail to understand why this PR exists providing:

  1. We cannot change MAJOR version of the package
  2. BREAKING CHANGE can be easily fixed
  3. This PR rollbacks to the wrong type definitions

@trim21 trim21 closed this Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants