如何将 AWS sdk 定义用于 TypeScript?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33225183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:06:46  来源:igfitidea点击:

How do I use AWS sdk definitions for TypeScript?

javascriptamazon-web-servicestypescript

提问by Jesse Barnum

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

我正在尝试使用从https://github.com/borisyankov/DefinitelyTyped/blob/master/aws-sdk/aws-sdk.d.ts下载的 AWS 定义文件编写 SES TypeScript 客户端

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!

我找不到有关如何进行这项工作的任何文档。请帮忙!

采纳答案by basarat

Change to :

改成 :

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

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

注意:如果import不清楚,您可能想阅读模块: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

提示:查看用于预期用途的测试文件总是一个好主意:https: //github.com/borisyankov/DefinitelyTyped/blob/master/aws-sdk/aws-sdk-tests.ts

回答by Michael Pell

I think a more appropriate way to do this is

我认为更合适的方法是

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

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

for instance

例如

import { DynamoDB } from 'aws-sdk';

import { DynamoDB } from 'aws-sdk';

followed by

其次是

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

this.client = new DynamoDB();在课堂里。

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

我说它更合适,因为它使用了 TypeScript 的导入语法。

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

此外,AWS 对如何在此处TS 与 AWS SDK一起使用有明确的解释。