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
[types/factory_girl] Refine initializer, attributes and buildOptions #50520
[types/factory_girl] Refine initializer, attributes and buildOptions #50520
Conversation
@@ -1,6 +1,6 @@ | |||
import * as factory from "factory-girl"; | |||
import * as factory from 'factory-girl'; |
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 applied Prettier in e97e0bc.
@@ -12,11 +12,20 @@ declare const factory: factory.Static; | |||
declare namespace factory { | |||
type Generator<T> = () => T; | |||
|
|||
type Definition<T> = T | Generator<T>; | |||
type Definition<T> = T | Generator<T> | Promise<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.
}>; | ||
}; | ||
|
||
type MaybeReadonlyArray<T> = T | ReadonlyArray<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.
Most of Factory#...Many()
function can take T
or ReadonlyArray<T>
for its attributes and options. So I defined a utility type for it.
|
||
/** | ||
* Builds an array of model instances that are persisted | ||
*/ | ||
buildMany<T>(name: string, num: number, attrs?: Attributes<Partial<T>>): Promise<T[]>; | ||
buildMany<T>(name: string, attrs?: ReadonlyArray<Attributes<Partial<T>>>): Promise<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.
As I investigated the implementation, Factory#buildMany(...)
needs num
parameter.
name: string, | ||
num: number, | ||
attrs?: MaybeReadonlyArray<Attributes<Partial<T>>>, | ||
buildOptions?: MaybeReadonlyArray<BuildOptions>, |
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.
A Options<T>
option can't be specified here. You can specify these options in Factory#define()
or Factory#extend()
.
Inspecting the JavaScript source for this package found some properties that are not in the .d.ts files. factory-girl (unpkg)was missing the following properties:
as well as these 1 other properties...ReduxORMAdapter |
👋 Hi there! I’ve run some quick measurements against master and your PR. These metrics should help the humans reviewing this PR gauge whether it might negatively affect compile times or editor responsiveness for users who install these typings. Let’s review the numbers, shall we? Comparison details 📊
It looks like nothing changed too much. I won’t post performance data again unless it gets worse. |
@ishikawa Thank you for submitting this PR! This is a live comment which I will keep updated. 1 package in this PR
Code ReviewsBecause you edited one package and updated the tests (👏), I can help you merge this PR once someone else signs off on it. 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": 50520,
"author": "ishikawa",
"headCommitOid": "30aa4563d38b96d01ea7955bb033fcf50dc17574",
"lastPushDate": "2021-01-11T02:06:07.000Z",
"lastActivityDate": "2021-01-28T14:38:12.000Z",
"maintainerBlessed": false,
"mergeOfferDate": "2021-01-28T13:06:48.000Z",
"mergeRequestDate": "2021-01-28T14:38:12.000Z",
"mergeRequestUser": "elcuy",
"hasMergeConflict": false,
"isFirstContribution": false,
"popularityLevel": "Well-liked by everyone",
"pkgInfo": [
{
"name": "factory-girl",
"kind": "edit",
"files": [
{
"path": "types/factory-girl/factory-girl-tests.ts",
"kind": "test"
},
{
"path": "types/factory-girl/index.d.ts",
"kind": "definition"
}
],
"owners": [
"stackbuilders",
"sestrella",
"elcuy",
"OlivierKamers"
],
"addedOwners": [],
"deletedOwners": [],
"popularityLevel": "Well-liked by everyone"
}
],
"reviews": [
{
"type": "approved",
"reviewer": "OlivierKamers",
"date": "2021-01-28T13:06:10.000Z",
"isMaintainer": false
}
],
"ciResult": "pass"
} |
🔔 @stackbuilders @sestrella @elcuy @OlivierKamers — please review this PR in the next few days. Be sure to explicitly select |
Re-ping @stackbuilders, @sestrella, @elcuy, @OlivierKamers: This PR has been out for over a week, yet I haven't seen any reviews. Could someone please give it some attention? Thanks! |
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.
Looks good! I linked these definitions to our project and it fixes some @ts-expect-errors we had 🎉
name: string, | ||
num: number, | ||
attrs?: MaybeReadonlyArray<Attributes<Partial<T>>>, | ||
buildOptions?: BuildOptions | ReadonlyArray<BuildOptions>, |
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.
Minor comment: you can use your MaybeReadonlyArray
utility type here
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.
Thanks! I hadn't noticed that. But sorry, it has been already merged 🙇
@ishikawa Everything looks good here. Great job! I am ready to merge this PR (at 30aa456) on your behalf. If you'd like that to happen, please post a comment saying:
and I'll merge this PR almost instantly. Thanks for helping out! ❤️ (@stackbuilders, @sestrella, @elcuy, @OlivierKamers: you can do this too.) |
1 similar comment
@ishikawa Everything looks good here. Great job! I am ready to merge this PR (at 30aa456) on your behalf. If you'd like that to happen, please post a comment saying:
and I'll merge this PR almost instantly. Thanks for helping out! ❤️ (@stackbuilders, @sestrella, @elcuy, @OlivierKamers: you can do this too.) |
Ready to merge |
I just published |
…zer, attributes and buildOptions by @ishikawa * prettier * update tests * update definitions
Please fill in this template.
npm test <package to test>
.Select one of these and delete the others:
If changing an existing definition: