Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use AWS sdk definitions for TypeScript?

Tags:

I am trying to write an SES TypeScript client, using AWS definitions file downloaded from https://github.com/borisyankov/DefinitelyTyped/blob/master/aws-sdk/aws-sdk.d.ts

Here is what I've tried:

/// <reference path="../typings/aws-sdk.d.ts" /> var AWS = require('aws-sdk');  var ses:SES = new AWS.SES(); 

Here is the error that I get:

/usr/local/bin/tsc --sourcemap SesTest.ts SesTest.ts(3,9): error TS2304: Cannot find name 'SES'.  Process finished with exit code 2 

I cannot find any documentation on how to make this work. Please help!

like image 237
Jesse Barnum Avatar asked Oct 19 '15 22:10

Jesse Barnum


People also ask

Which command may be used to import the AWS SDK for JavaScript into a JavaScript module?

The preferred way to install the AWS SDK for JavaScript for Node. js is to use npm, the Node. js package manager . To do so, type this at the command line.

Does AWS support TypeScript?

TypeScript is a fully-supported client language for the AWS CDK and is considered stable. Working with the AWS CDK in TypeScript uses familiar tools, including Microsoft's TypeScript compiler ( tsc ), Node. js and the Node Package Manager ( npm ).

What is TS SDK?

The Temporal TypeScript SDK lets you write highly scalable and reliable long-running Workflows without being a distributed systems expert. It is designed with TypeScript-first developer experience in mind, but works equally well with JavaScript.


2 Answers

I think a more appropriate way to do this is

import { <ServiceName> } from 'aws-sdk';

for instance

import { DynamoDB } from 'aws-sdk';

followed by

this.client = new DynamoDB(); in the class.

I say it is more appropriate because it uses TypeScript's import syntax.

Also, there's a clear explanation - by AWS - on how to use TS with AWS SDK here.

like image 139
Michael Pell Avatar answered Oct 22 '22 21:10

Michael Pell


Change to :

import AWS = require('aws-sdk');  var ses:AWS.SES = new AWS.SES(); 

Note: if import is unclear you probably want to read up on modules : https://basarat.gitbooks.io/typescript/content/docs/project/modules.html

TIP: always a good idea to see the test file for intended usage : https://github.com/borisyankov/DefinitelyTyped/blob/master/aws-sdk/aws-sdk-tests.ts

like image 36
basarat Avatar answered Oct 22 '22 23:10

basarat