简体   繁体   English

如何为TypeScript使用AWS sdk定义?

[英]How do I use AWS sdk definitions for TypeScript?

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! 请帮忙!

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. 我说它更合适,因为它使用TypeScript的导入语法。

Also, there's a clear explanation - by AWS - on how to use TS with AWS SDK here . 此外,有一个明确的解释 - 由AWS - 如何在这里使用TS与AWS SDK

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 注意:如果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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获得AWS上的凭证? 我必须使用AWS Cognito SDK还是AWS SDK? - How do I get credentials on AWS? Must I use AWS Cognito SDK or AWS SDK? 如何在 TypeScript 中使用“then”? - How do I use “then” with TypeScript? 如何在 TypeScript 中使用包含的 Axios 类型定义进行依赖注入 - How can I use the included Axios Type definitions for dependency injection in TypeScript 如何在许多Visual Studio(2013)项目中处理TypeScript类型定义? - How do I handle TypeScript type definitions across many Visual Studio (2013) projects? 如何在angular cli应用程序中使用typescript声明(.ts.d文件)来使用第三方javascript API / SDK? - How Do I use typescript declarations (.ts.d files) to consume a third party javascript API / SDK in an angular cli application? 如何在 TypeScript 中使用 RequestPromise? - How do I use RequestPromise in TypeScript? 如何在ReactJS中使用AWS sdk的自定义版本? - How can I use a customized build of the AWS sdk in ReactJS? 如何使用 Twit 的 Typescript 定义; 回调函数不可分配 - how to use Twit's Typescript definitions; Callback function not assignable 如何使用AWS节点SDK在托管区域中创建A记录 - How do I create an A record in a hosted zone with the AWS node SDK 如何排除TypeScript定义中声明的全局类型? - How do you exclude global types declared in TypeScript definitions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM