0
我收到以下错误,当我使用AWS-SDK在angular2(打字稿)打字稿多返回类型的方法不占
import * as AWS from 'aws-sdk';
AWS.config.credentials.get
[ts]
Property 'get' does not exist on type 'Credentials | CredentialsOptions'.
Property 'get' does not exist on type 'CredentialsOptions'.
得到CredentialsOptions不存在,但它确实凭据存在。由于这个原因,Typescript不断抛弃我。有什么建议么?这是打字稿中的错误吗?
我使用“打字稿”:“〜2.3.3”
https://github.com/aws/aws-sdk-js#pre-requisites – JGFMK
在TS的错误吗?不,这是正确的行为;该方法不在两个可能的返回值上,所以你(和编译器)不能假设它会在那里。你可以自己缩小它,例如'(AWS.config.credentials as Credentials).get',但是如果这不是你实际得到的代码在运行时会失败。 – jonrsharpe
谢谢@jonrsharpe。这是有道理的,尽管typecript随机选择一种返回类型有点混乱。 – Prabhat