googleapis / nodejs-logging-bunyan

Node.js client integration between Stackdriver Logging and Bunyan.
https://cloud.google.com/logging/
Apache License 2.0
63 stars 34 forks source link

Recommended way for middleware + typescript #674

Closed gugahoi closed 10 months ago

gugahoi commented 1 year ago

Just wondering what the recommended way to use this package's middleware with typescript. Is there a type to use for the request so that the compiler can understand the log calls? Currently I get the following error:

Screen Shot 2022-11-23 at 2 37 03 pm

Do I need to extend the type definitions myself?

yfr commented 1 year ago

A little late but maybe of help still:

import {Logger} from '@google-cloud/logging-bunyan/build/src/middleware/express';

declare global {
  namespace Express {
    export interface Request {
      log: Logger;
    }
  }
}

This extends the request object of typescript globally.

cindy-peng commented 10 months ago

Hi @gugahoi, yes you can extend the type definition yourself to use this middleware in typescript. At this moment, we don't export the extended Request type in this library.