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

feat(sinon): add define method to sandboxes #66888

Merged
merged 1 commit into from
Oct 2, 2023

Conversation

43081j
Copy link
Contributor

@43081j 43081j commented Oct 1, 2023

This allows you to define an arbitrary property on an object for the lifetime of the sandbox.

Purposely doesn't use generics since you should be able to define properties the object's type doesn't have.

Please fill in this template.

This allows you to define an arbitrary property on an object for the lifetime
of the sandbox.

Purposely doesn't use generics since you should be able to define properties
the object's type doesn't have.
@typescript-bot
Copy link
Contributor

typescript-bot commented Oct 1, 2023

@43081j 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": 66888,
  "author": "43081j",
  "headCommitOid": "66924daa0ba7976668bd572f4b1f8f5135b7301f",
  "mergeBaseOid": "62e861498b0c5a98468c18624877a046ec9ae0b8",
  "lastPushDate": "2023-10-01T11:12:49.000Z",
  "lastActivityDate": "2023-10-02T19:57:17.000Z",
  "mergeOfferDate": "2023-10-02T19:38:49.000Z",
  "mergeRequestDate": "2023-10-02T19:57:17.000Z",
  "mergeRequestUser": "43081j",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "sinon",
      "kind": "edit",
      "files": [
        {
          "path": "types/sinon/index.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/sinon/sinon-tests.ts",
          "kind": "test"
        }
      ],
      "owners": [
        "mrbigdog2u",
        "nicojs",
        "43081j",
        "gjednaszewski",
        "johnjesse",
        "alecf",
        "SimonSchick",
        "lo1tuma"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "rbuckton",
      "date": "2023-10-02T19:38:04.000Z",
      "isMaintainer": true
    }
  ],
  "mainBotCommentID": 1742046535,
  "ciResult": "pass"
}

@typescript-bot typescript-bot added Critical package Author is Owner The author of this PR is a listed owner of the package. labels Oct 1, 2023
@typescript-bot
Copy link
Contributor

🔔 @MrBigDog2U @nicojs @gjednaszewski @johnjesse @alecf @SimonSchick @lo1tuma — 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 Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner labels Oct 2, 2023
@43081j
Copy link
Contributor Author

43081j commented Oct 2, 2023

ready to merge 🍻

@typescript-bot typescript-bot merged commit a6b3449 into DefinitelyTyped:master Oct 2, 2023
@43081j 43081j deleted the sinon-define branch October 3, 2023 11:45
*/
define(
obj: object,
key: PropertyKey,
Copy link

@gukoff gukoff Nov 16, 2023

Choose a reason for hiding this comment

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

Purposely doesn't use generics since you should be able to define properties the object's type doesn't have

@43081j hey, there's some inconvenience that I believe is caused by the lack of generics.

The property passed to .define() might or might not be declared in the class definition. In my case, the properties are declared, and I'd like the IDE to be able to jump to the property definition.

With sandbox.replace(), the IDE understands that the argument is an actual property:

image

And with sandbox.define(), it doesn't. IDE thinks it's just a string.


I'm not well-versed in how these type definitions work, please help me understand.
Would it make sense to declare this type as a union of PropertyKey and TKey extends keyof T?

Copy link

Choose a reason for hiding this comment

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

I verified that property discovery in WebStorm works well when the type is declared as keyof T | PropertyKey.

Here's PR with a corresponding change:
#67433

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author is Owner The author of this PR is a listed owner of the package. 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.

4 participants