gatsbyz
gatsbyz

Reputation: 1075

What could be the type of the imported aws-sdk object? (aws-sdk-js/ts/)

import * as aws from 'aws-sdk';

export default (env: any) => (context: Context): ###type of aws-sdk### => {
    (timeout config stuff)
    (connection config stuff)
    return aws;
}

I'm trying to use the aws-sdk as an object and need help with typing. I have some custom code for timeouts so I can't import aws-sdk directly.

Upvotes: 0

Views: 293

Answers (1)

Matt McCutchen
Matt McCutchen

Reputation: 30999

If you need to refer to the type of aws, you can write typeof aws. But in the example code you gave, you can just leave off the annotation and TypeScript will infer the return type of the inner arrow function to be the equivalent of typeof aws anyway.

As an example for a method signature:

public doSomething(awsInstance : typeof AWS) : void {
  // Do something with the AWS object.
}

Upvotes: 1

Related Questions