Add JSDoc type hints throughout replsettest.js

XMLWordPrintableJSON

    • Type: Task
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Replication
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Most of the methods in jstests/libs/replsettest.js have minimal or no JSDoc comments. As a result, when writing jstests, our code editors have no idea what the types of any of our variables are. Because of this, they are unable to display autocomplete suggestions and it is easy to make mistakes like this:

      const rst = new ReplSetTest({"name": jsTestName(), "nodes": 1});
      rst.startSet();
      rst.initiate();
      
      const size = rst.getPrimary().getDB("test")["foo"].getTotalSize();
      assert.eq(0, size);
      

      Adding a one-line JSDoc comment like the one below allows code editors to pick up on the type definitions in shell/mongo.d.ts, shell/db.d.ts, etc.:

      // jstests/libs/replsettest.js
      
      /**
       * @returns {Mongo}
       */
      getPrimary(timeout, retryIntervalMS) {
      

      and now hovering over the end of the last method call reveals the mistake. Furthermore, just typing "tot" will autocomplete to "totalSize".

      const primary = rst.getPrimary();
      
      const sizeWrong   = primary.getDB("test")["foo"].getTotalSize();
      //                                               ^? any
      
      const sizeCorrect = primary.getDB("test")["foo"].totalSize();
      //                                               ^? (method) DBCollection.totalSize()
      

            Assignee:
            Unassigned
            Reporter:
            Joseph Obaraye
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: