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

[@types/mongoose]: fix array handling in create #45355

Merged

Conversation

andreialecu
Copy link
Contributor

This PR fixes two edge cases when using the new types added for .create().

I have added two tests that were previously failing.

Reported on typegoose/typegoose#290

Please fill in this template.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • Add or edit tests to reflect the change. (Run with npm test.)
  • Follow the advice from the readme.
  • Avoid common mistakes.
  • Run npm run lint package-name (or tsc if no tslint.json is present).

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.
  • Include tests for your changes
  • If you are making substantial changes, consider adding a tslint.json containing { "extends": "dtslint/dt.json" }. If for reason the any rule need to be disabled, disable it for that line using // tslint:disable-next-line [ruleName] and not for whole package so that the need for disabling can be reviewed.

@typescript-bot
Copy link
Contributor

typescript-bot commented Jun 8, 2020

@andreialecu Thank you for submitting 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.

Status

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

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": 45355,
  "author": "andreialecu",
  "owners": [
    "horiuchi",
    "lukasz-zak",
    "jendrikw",
    "ethanresnick",
    "vologab",
    "jussikinnula",
    "ondratra",
    "alfirin",
    "idandrd",
    "various89",
    "Fazendaaa",
    "NormanPerrin",
    "stablio",
    "emmanuelgautier",
    "frontendmonster",
    "mingchen",
    "penumbra1",
    "orblazer",
    "HughKu",
    "niuware",
    "vladmel1234",
    "jloveridge",
    "grimmer0125",
    "richarddd",
    "ToucheSir",
    "borfig",
    "dinodeSimon",
    "anthony-kenikh",
    "iamchathu",
    "lkho",
    "tomyam1",
    "nephix",
    "rlaace423",
    "ChazEpps",
    "avaly",
    "JanNemcik",
    "cl3dson",
    "richardsimko",
    "ith",
    "jeremyben",
    "andreialecu",
    "tHBp"
  ],
  "dangerLevel": "ScopedAndTested",
  "headCommitAbbrOid": "8c5494c",
  "headCommitOid": "8c5494cbfe2dcf41e36b080428e29a3e45f28ce4",
  "mergeIsRequested": true,
  "stalenessInDays": 0,
  "lastCommitDate": "2020-06-18T12:22:56.000Z",
  "reopenedDate": "2020-06-08T18:20:31.000Z",
  "lastCommentDate": "2020-06-18T13:05:21.000Z",
  "reviewLink": "https://github.com/DefinitelyTyped/DefinitelyTyped/pull/45355/files",
  "hasMergeConflict": false,
  "authorIsOwner": true,
  "isFirstContribution": false,
  "popularityLevel": "Popular",
  "anyPackageIsNew": false,
  "packages": [
    "mongoose"
  ],
  "files": [
    {
      "filePath": "types/mongoose/index.d.ts",
      "kind": "definition",
      "package": "mongoose"
    },
    {
      "filePath": "types/mongoose/test/model.ts",
      "kind": "test",
      "package": "mongoose"
    }
  ],
  "hasDismissedReview": false,
  "ciResult": "pass",
  "lastReviewDate": "2020-06-18T13:00:35.000Z",
  "reviewersWithStaleReviews": [],
  "approvalFlags": 2,
  "isChangesRequested": false
}

@typescript-bot
Copy link
Contributor

@danger-public
Copy link

danger-public commented Jun 8, 2020

Inspecting the JavaScript source for this package found some properties that are not in the .d.ts files.
The check for missing properties isn't always right, so take this list as advice, not a requirement.

mongoose (unpkg)

was missing the following properties:

  1. modelSchemas
  2. options
  3. cast
  4. driver
  5. deleteModel
as well as these 7 other properties...

ObjectId, Decimal128, Mixed, Number, now, CastError, SchemaTypeOptions

Generated by 🚫 dangerJS against 8c5494c

@typescript-bot typescript-bot added Popular package This PR affects a popular package (as counted by NPM download counts). Author is Owner The author of this PR is a listed owner of the package. labels Jun 8, 2020
@typescript-bot typescript-bot added this to Waiting for Code Reviews in New Pull Request Status Board Jun 8, 2020
@andreialecu andreialecu marked this pull request as draft June 8, 2020 12:47
@andreialecu andreialecu marked this pull request as ready for review June 8, 2020 13:47
@typescript-bot
Copy link
Contributor

👋 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?

master #45355 diff
Batch compilation
Memory usage (MiB) 122.4 129.4 +5.7%
Type count 52370 58192 +11%
Assignability cache size 18660 19580 +5%
Language service
Samples taken 1636 1698 +4%
Identifiers in tests 5606 5668 +1%
getCompletionsAtPosition
    Mean duration (ms) 440.7 463.1 +5.1%
    Mean CV 10.1% 9.1%
    Worst duration (ms) 943.1 1204.3 +27.7% 🔸
    Worst identifier mongoModel ref
getQuickInfoAtPosition
    Mean duration (ms) 449.7 470.8 +4.7%
    Mean CV 10.1% 8.8% -12.5%
    Worst duration (ms) 953.0 947.8 -0.5%
    Worst identifier model model

Looks like there were a couple significant differences—take a look at worst-case duration for getting completions at a position to make sure everything looks ok.

@typescript-bot typescript-bot added the Perf: Worse typescript-bot determined that this PR has a negative impact on compilation performance. label Jun 8, 2020
@andreialecu andreialecu marked this pull request as draft June 8, 2020 18:04
@andreialecu andreialecu marked this pull request as ready for review June 8, 2020 18:20
@andreialecu
Copy link
Contributor Author

I'm the original author of the .create() types that were recently merged, this is a bug fix for some edge cases.

@typescript-bot
Copy link
Contributor

Updated numbers for you here from 875b47e. Nice job, these numbers look better.

Comparison details 📊
master #45355 diff
Batch compilation
Memory usage (MiB) 112.6 126.8 +12.6%
Type count 52370 58109 +11%
Assignability cache size 18660 19610 +5%
Language service
Samples taken 1675 1707 +2%
Identifiers in tests 5606 5677 +1%
getCompletionsAtPosition
    Mean duration (ms) 433.1 438.2 +1.2%
    Mean CV 9.1% 9.1%
    Worst duration (ms) 1044.6 1224.7 +17.2%
    Worst identifier find ref
getQuickInfoAtPosition
    Mean duration (ms) 442.0 447.0 +1.1%
    Mean CV 8.9% 9.0% +0.8%
    Worst duration (ms) 959.7 912.2 -4.9%
    Worst identifier _id model

It looks like nothing changed too much. I won’t post performance data again unless it gets worse.

@typescript-bot typescript-bot added Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance. and removed Perf: Worse typescript-bot determined that this PR has a negative impact on compilation performance. labels Jun 8, 2020
@typescript-bot
Copy link
Contributor

Updated numbers for you here from 507c871.

Comparison details 📊
master #45355 diff
Batch compilation
Memory usage (MiB) 123.9 125.6 +1.3%
Type count 52370 54505 +4%
Assignability cache size 18660 17257 -8%
Language service
Samples taken 1636 1707 +4%
Identifiers in tests 5606 5677 +1%
getCompletionsAtPosition
    Mean duration (ms) 434.7 434.8 0.0%
    Mean CV 9.3% 9.1%
    Worst duration (ms) 900.4 1151.0 +27.8% 🔸
    Worst identifier mongoModel ref
getQuickInfoAtPosition
    Mean duration (ms) 444.2 443.9 -0.1%
    Mean CV 9.2% 9.3% +0.6%
    Worst duration (ms) 953.0 847.9 -11.0%
    Worst identifier model model

Looks like there were a couple significant differences—take a look at worst-case duration for getting completions at a position to make sure everything looks ok.

@typescript-bot typescript-bot added Perf: Worse typescript-bot determined that this PR has a negative impact on compilation performance. and removed Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance. labels Jun 9, 2020
@andreialecu
Copy link
Contributor Author

Performance is slightly worse because of the added tests, the bot measures completion times for what appears in tests, and the "worst case identifier" comes from a new test I added.

@orta
Copy link
Collaborator

orta commented Jun 10, 2020

Any chance we can get an aye in from another module owner? ( Looks good in general to me )

@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Review in New Pull Request Status Board Jun 14, 2020
@andreialecu
Copy link
Contributor Author

Bump?

@jeremyben
Copy link
Contributor

Looks good to me as well.
Just a question about a line in the tests:

selfRefArray?: (ModelWithFunction | mongodb.ObjectID | undefined)[];

Usually, when I want to mark a field as an array of references (to be populated), I go with this union:

selfRefArray?: ModelWithFunction[] | mongodb.ObjectID[];

which is closer the the behavior of populate.

I just want to make sure either way is fine.

@andreialecu
Copy link
Contributor Author

I will add a test shortly for that too @jeremyben to ensure it doesn't regress in the future.

The test is written that way to expose an edge case which was occuring in typegoose

@typescript-bot typescript-bot moved this from Needs Maintainer Review to Waiting for Code Reviews in New Pull Request Status Board Jun 18, 2020
@andreialecu
Copy link
Contributor Author

Alright, test added and passing @jeremyben

@typescript-bot typescript-bot added Owner Approved A listed owner of this package signed off on the pull request. Self Merge This PR can now be self-merged by the PR author or an owner labels Jun 18, 2020
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Waiting for Author to Merge in New Pull Request Status Board Jun 18, 2020
@andreialecu
Copy link
Contributor Author

Ready to merge

@typescript-bot typescript-bot moved this from Waiting for Author to Merge to Recently Merged in New Pull Request Status Board Jun 18, 2020
@typescript-bot typescript-bot merged commit 11c8931 into DefinitelyTyped:master Jun 18, 2020
@typescript-bot
Copy link
Contributor

I just published @types/mongoose@5.7.27 to npm.

@typescript-bot
Copy link
Contributor

Updated numbers for you here from cf000ce. Nice job, these numbers look better.

Comparison details 📊
master #45355 diff
Batch compilation
Memory usage (MiB) 143.1 138.9 -2.9%
Type count 68320 67637 -1%
Assignability cache size 20098 18866 -6%
Language service
Samples taken 2272 1797 -21%
Identifiers in tests 5687 5780 +2%
getCompletionsAtPosition
    Mean duration (ms) 408.0 445.9 +9.3%
    Mean CV 9.2% 9.4%
    Worst duration (ms) 1422.2 1410.8 -0.8%
    Worst identifier _id mongoModel
getQuickInfoAtPosition
    Mean duration (ms) 421.5 456.0 +8.2%
    Mean CV 9.3% 9.2% -1.0%
    Worst duration (ms) 1665.9 1359.2 -18.4%
    Worst identifier err model

It looks like nothing changed too much. I won’t post performance data again unless it gets worse.

@typescript-bot typescript-bot added Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance. and removed Perf: Worse typescript-bot determined that this PR has a negative impact on compilation performance. labels Jun 18, 2020
vanessayuenn pushed a commit to vanessayuenn/DefinitelyTyped that referenced this pull request Jun 23, 2020
…g in create by @andreialecu

* fix(mongoose): enum arrays in .create()

* fix optionals changing to non nullable

* update tests

* revert previous commit and fix properly

* fix undefined in array, and simplify type

* cleanup

* add additional tests
ngbrown pushed a commit to ngbrown-forks/DefinitelyTyped that referenced this pull request Jul 11, 2020
…g in create by @andreialecu

* fix(mongoose): enum arrays in .create()

* fix optionals changing to non nullable

* update tests

* revert previous commit and fix properly

* fix undefined in array, and simplify type

* cleanup

* add additional tests
@typescript-bot typescript-bot removed this from Recently Merged in New Pull Request Status Board Jul 13, 2020
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. Owner Approved A listed owner of this package signed off on the pull request. Perf: Same typescript-bot determined that this PR will not significantly impact compilation performance. Popular package This PR affects a popular package (as counted by NPM download counts). 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

5 participants