简体   繁体   中英

AWS X-ray import with Typescript

I currently use postgresql-node in my lambda with

import { Client } from 'pg'

I want to instrument the Postgresql lib with AWS X-ray. The Nodejs example has this line:

var AWSXRay = require('aws-xray-sdk');
var pg = AWSXRay.capturePostgres(require('pg'));

How would I convert the second line in that to proper Typescript. All the variations I come up with produce some errors or warnings. For example I would guess this would work:

const pg = AWSXRay.capturePostgres(require('pg'))

but not only you get ESlint warning for require being used without import but after that pg.Client says pg namespace not found .

Well, it's slightly ugly but this seems to work:

import * as pg from 'pg'
const patchedPg = AWSXRay.capturePostgres(pg)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM