0

I am using langchain library in NestJS. Langchain is ESM so following docs I have added a dynamic import like so:

@Injectable()
export class LangchainService {
  public openAI: any;

  constructor() {
    this.loadOpenAI();
  }

  private async loadOpenAI() {
    const { OpenAI } = await import('langchain');
    this.openAI = new OpenAI(/* your config here */);
  }

}

But I don't want openAI property to be any. How do I give it a type?

This is my tsconfig:

{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node16",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "target": "ESNext",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "incremental": true,
    "skipLibCheck": true,
    "strictNullChecks": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false,
    "paths": {
      "*": ["node_modules/*"]
    }
  }
}

Guerrilla
  • 13,375
  • 31
  • 109
  • 210

0 Answers0