-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
Conversation
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.
@43081j Thank you for submitting this PR! This is a live comment which I will keep updated. 1 package in this PRCode ReviewsBecause 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
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"
} |
🔔 @MrBigDog2U @nicojs @gjednaszewski @johnjesse @alecf @SimonSchick @lo1tuma — please review this PR in the next few days. Be sure to explicitly select |
ready to merge 🍻 |
*/ | ||
define( | ||
obj: object, | ||
key: PropertyKey, |
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.
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:
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
?
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.
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
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.
npm test <package to test>
.