Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-3115

Make use of TypeScript generic types

    XMLWordPrintable

Details

    • Improvement
    • Status: Closed
    • Critical - P2
    • Resolution: Fixed
    • 4.0.0
    • 4.0.0
    • Lambda
    • Needed
    • Hide
      Recommend users who utilize typescript can use generics to get autocomplete on their data models.

      (We aren't 100% sure how the docs team would like to handle the typescript related documentation, so airing on the side of overcommunication. Please reach out with any questions!)
      Show
      Recommend users who utilize typescript can use generics to get autocomplete on their data models. (We aren't 100% sure how the docs team would like to handle the typescript related documentation, so airing on the side of overcommunication. Please reach out with any questions!)

    Description

      I just tried migrating our platform to the new beta MongoDB driver to see if everything still works fine and I had to manually cast a lot of things manually because the generic types are gone.

       

      An example diff from our code base (before/after):

      diff --git a/apps/lambda-kyc/src/entities/mentor-limitchange-stats.entity.ts b/apps/lambda-kyc/src/entities/mentor-limitchange-stats.entity.ts
      index 5e722dd8a..a2242b18c 100644
      --- a/apps/lambda-kyc/src/entities/mentor-limitchange-stats.entity.ts
      +++ b/apps/lambda-kyc/src/entities/mentor-limitchange-stats.entity.ts
      @@ -32,7 +32,7 @@ export class MentorLimitChangeStats extends Entity {
         static async getAggregatedByHour(brandId: string, hour: number) {
           const db = Container.get(MongoClient);
           const mentorLimitChangeStatsCollection = await db.getCollection<MentorLimitChangeStats>(MentorLimitChangeStats.__name);
      -    const hourAggregate = mentorLimitChangeStatsCollection.aggregate<{ _id: null; total: number }>([
      +    const hourAggregate = mentorLimitChangeStatsCollection.aggregate([
             {
               $match: {
                 brandId,
      @@ -48,7 +48,7 @@ export class MentorLimitChangeStats extends Entity {
               },
             },
           ]);
      -    return hourAggregate.toArray();
      +    return hourAggregate.toArray() as Promise<Array<{ _id: null; total: number }>>;
         }   async updateFromAggregateEvent<P extends EventPayload>(sourceEvent: AggregateEvent<P>) {
      

       

      If you check the types from DefinitelyTyped for the current version you will see what I mean: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/mongodb/index.d.ts#L1236

      Attachments

        Issue Links

          Activity

            People

              neal.beeken@mongodb.com Neal Beeken
              joao.dias@themill.io Joao Dias
              Votes:
              2 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: