I'm a newbie to typescript
Currently i have 2 files contains 2 classes which import each others utils which has s3 class as a property
Utils.ts:
import { S3Storage } from '../storage/s3';
export class Utils {
static s3Writer = new S3Storage(env.buckerName);
static async UtilsMethod(){
};
}
and s3 which use utils class method
S3.ts:
import { Utils } from '../util/utils';
export class S3Storage {
constructor(bucketName) {
const AWS_ID = process.env.AWS_ACCESS_KEY_ID;
const AWS_KEY = process.env.AWS_SECRET_ACCESS_KEY;
const AWS_REGION = process.env.AWS_REGION;
const AWS_ID_VIEW = AWS_ID.substring(AWS_ID.length - 4, AWS_ID.length);
const AWS_KEY_VIEW = AWS_KEY.substring(AWS_KEY.length - 4, AWS_KEY.length);
this.logger.info(`Setting up s3PageWriter to bucket: ${bucketName}`);
this.logger.info(`ID: ${AWS_ID_VIEW}`);
this.logger.info(`Key: ${AWS_KEY_VIEW}`);
AWS.config.apiVersions = { s3: '2006-03-01' };
AWS.config.update({
region: AWS_REGION,
});
this.bucketName = bucketName;
this.s3 = new AWS.S3({
accessKeyId: AWS_ID,
secretAccessKey: AWS_KEY,
});
}
async s3Method(){
Utils.UtilsMethod();
}
}
EDIT: the first time i though it's circular import because it work when i removed the import Utils from my s3 but now i don't think that the reason. I got this error before if i tried to run from the first example
export class Utils {
^
TypeError: s3_1.S3Storage is not a constructor
even though my s3 class has constructor
export class S3Storage {
logger = require('../util/log')(this.constructor.name);
bucketName: string;
s3;
constructor(bucketName) {
...
}
}