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

jquery: Specialize .val() for elements with known value types #66801

Merged
merged 1 commit into from Oct 4, 2023

Conversation

andersk
Copy link
Contributor

@andersk andersk commented Sep 22, 2023

If the user explicitly provides a specific element class like $<HTMLInputElement>("input").val(), this lets us infer the result as string | undefined rather than string | number | string[] | undefined.

Please fill in this template.

Select one of these and delete the others:

If changing an existing definition:

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
@typescript-bot
Copy link
Contributor

typescript-bot commented Sep 22, 2023

@andersk Thank you for submitting this PR!

This is a live comment which I will keep updated.

1 package in this PR

Code Reviews

Because this is a widely-used package, a DT maintainer will need to review it before it can be merged.

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 a DT maintainer

All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 66801,
  "author": "andersk",
  "headCommitOid": "5b98d0468e07c4134fcbbf2f0459f50990ea9e73",
  "mergeBaseOid": "027ee9cdb7d69d3a06d8420341e9231e10bfaa77",
  "lastPushDate": "2023-09-22T20:54:02.000Z",
  "lastActivityDate": "2023-10-04T22:21:47.000Z",
  "mergeOfferDate": "2023-10-04T19:27:12.000Z",
  "mergeRequestDate": "2023-10-04T22:21:47.000Z",
  "mergeRequestUser": "andersk",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "jquery",
      "kind": "edit",
      "files": [
        {
          "path": "types/jquery/JQuery.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/jquery/test/val.ts",
          "kind": "test"
        },
        {
          "path": "types/jquery/tsconfig.json",
          "kind": "package-meta-ok"
        }
      ],
      "owners": [
        "leonard-thieu",
        "borisyankov",
        "choffmeister",
        "Steve-Fenton",
        "Diullei",
        "tasoili",
        "seanski",
        "Guuz",
        "ksummerlin",
        "basarat",
        "nwolverson",
        "derekcicerone",
        "AndrewGaspar",
        "seikichi",
        "benjaminjackman",
        "JoshStrobl",
        "johnnyreilly",
        "DickvdBrink",
        "King2500",
        "terrymun",
        "martin-badin",
        "princefishthrower"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "johnnyreilly",
      "date": "2023-10-04T19:26:26.000Z",
      "isMaintainer": true
    }
  ],
  "mainBotCommentID": 1732022687,
  "ciResult": "pass"
}

@typescript-bot
Copy link
Contributor

🔔 @leonard-thieu @borisyankov @choffmeister @Steve-Fenton @Diullei @tasoili @seanski @Guuz @ksummerlin @basarat @nwolverson @derekcicerone @AndrewGaspar @seikichi @benjaminjackman @JoshStrobl @johnnyreilly @DickvdBrink @King2500 @terrymun @martin-badin @princefishthrower — 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 this to Waiting for Code Reviews in New Pull Request Status Board Sep 22, 2023
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Review in New Pull Request Status Board Sep 22, 2023
@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 Oct 4, 2023
@typescript-bot
Copy link
Contributor

Re-ping @leonard-thieu, @borisyankov, @choffmeister, @Steve-Fenton, @Diullei, @tasoili, @seanski, @Guuz, @ksummerlin, @basarat, @nwolverson, @derekcicerone, @AndrewGaspar, @seikichi, @benjaminjackman, @JoshStrobl, @johnnyreilly, @DickvdBrink, @King2500, @terrymun, @martin-badin, @princefishthrower:

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

Could someone please give it some attention? Thanks!

@Steve-Fenton
Copy link
Member

Hey @andersk - I couldn't see an example in your tests that demonstrates the HTML Input case you mention in the description. I might just be missing it. I can see you handling the scenarios for single and multi-selected, but not the one that demonstrates the input with the expected string | null type.

@andersk
Copy link
Contributor Author

andersk commented Oct 4, 2023

@Steve-Fenton We never expect string | null; I assume you mean string | undefined. That’s the first test case, and it includes HTMLInputElement on line 4.

let string_val: string | undefined = $<
| HTMLButtonElement
| HTMLDataElement
| HTMLInputElement
| HTMLOptionElement
| HTMLOutputElement
| HTMLParamElement
| (HTMLSelectElement & { type: 'select-one' })
| HTMLTextAreaElement
>('button, data, input, option, output, param, select:not([multiple]), textarea').val();

@Steve-Fenton
Copy link
Member

@andersk Yep. I missed it! Thanks for that.

@Steve-Fenton
Copy link
Member

@johnnyreilly this looks okay to me!

@typescript-bot typescript-bot added Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner and removed Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. labels Oct 4, 2023
@typescript-bot typescript-bot moved this from Needs Maintainer Review to Waiting for Author to Merge in New Pull Request Status Board Oct 4, 2023
@typescript-bot
Copy link
Contributor

@andersk: Everything looks good here. I am ready to merge this PR (at 5b98d04) on your behalf whenever you think it's ready.

If you'd like that to happen, please post a comment saying:

Ready to merge

and I'll merge this PR almost instantly. Thanks for helping out! ❤️

(@leonard-thieu, @borisyankov, @choffmeister, @Steve-Fenton, @Diullei, @tasoili, @seanski, @Guuz, @ksummerlin, @basarat, @nwolverson, @derekcicerone, @AndrewGaspar, @seikichi, @benjaminjackman, @JoshStrobl, @johnnyreilly, @DickvdBrink, @King2500, @terrymun, @martin-badin, @princefishthrower: you can do this too.)

@andersk
Copy link
Contributor Author

andersk commented Oct 4, 2023

Ready to merge

@typescript-bot typescript-bot moved this from Waiting for Author to Merge to Recently Merged in New Pull Request Status Board Oct 4, 2023
@typescript-bot typescript-bot merged commit 4945dd6 into DefinitelyTyped:master Oct 4, 2023
2 checks passed
@typescript-bot typescript-bot removed this from Recently Merged in New Pull Request Status Board Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Critical package Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants