如何为TypeScript使用AWS sdk定义?

时间:2022-02-09 13:28:11

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!

我找不到任何关于如何使这项工作的文件。请帮忙!

2 个解决方案

#1


7  

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

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

#2


9  

I think a more appropriate way to do this is

我认为更合适的方法是这样做

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

从'aws-sdk'导入{ };

for instance

例如

import { DynamoDb } from 'aws-sdk';

从'aws-sdk'导入{DynamoDb};

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的导入语法。

#1


7  

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

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

#2


9  

I think a more appropriate way to do this is

我认为更合适的方法是这样做

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

从'aws-sdk'导入{ };

for instance

例如

import { DynamoDb } from 'aws-sdk';

从'aws-sdk'导入{DynamoDb};

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的导入语法。