首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在打字稿中获取aws-cdk错误

在打字稿中获取aws-cdk错误
EN

Stack Overflow用户
提问于 2022-04-18 18:15:46
回答 1查看 508关注 0票数 -3

如何解决类型记录中的这些错误--我已经用cdk innit app --language typescript创建了这些错误。Vscode在配置中突出显示timeoutexpires属性。

我在lib文件夹中的构造函数是

代码语言:javascript
复制
import * as cdk from "@aws-cdk/core";
import * as appsync from "@aws-cdk/aws-appsync";
import * as lambda from "@aws-cdk/aws-lambda";

export class Step03GraphQlStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const api = new appsync.GraphqlApi(this, "GRAPHQL_API", {
      name: "cdk-api",
      schema: appsync.Schema.fromAsset("graphql/schema.gql"), 
      authorizationConfig: {
        defaultAuthorization: {
          authorizationType: appsync.AuthorizationType.API_KEY, 
           apiKeyConfig: {
            expires: cdk.Expiration.after(cdk.Duration.days(365)), 
           },
        },
      },
      xrayEnabled: true, 
    });
    new cdk.CfnOutput(this, "APIGraphQlURL", {
      value: api.graphqlUrl,
    });
    new cdk.CfnOutput(this, "GraphQLAPIKey", {
      value: api.apiKey || "",
    });
    const lambda_function = new lambda.Function(this, "LambdaFucntion", {
      runtime: lambda.Runtime.NODEJS_12_X, 
      code: lambda.Code.fromAsset("lambda"), 
      handler: "index.handler", ///specfic fucntion in specific file
      timeout: cdk.Duration.seconds(10), 
    });
    const lambda_data_source = api.addLambdaDataSource(
      "lamdaDataSource",
      lambda_function
    );
    lambda_data_source.createResolver({
      typeName: "Query",
      fieldName: "notes",
    });

    lambda_data_source.createResolver({
      typeName: "Query",
      fieldName: "customNote",
    });
  }
}

在运行tsc时,我会得到这些错误。

代码语言:javascript
复制
D:\Unicorn\cdk\step03_graphQl>tsc
lib/step03_graph_ql-stack.ts:17:13 - error TS2322: Type 'import("D:/Unicorn/cdk/step03_graphQl/node_modules/@aws-cdk/core/lib/expiration").Expiration' is not assignable to type 'import("D:/Unicorn/cdk/step03_graphQl/node_modules/@aws-cdk/aws-appsync/node_modules/@aws-cdk/core/lib/expiration").Expiration'.
  Types of property 'isBefore' are incompatible.
    Type '(t: import("D:/Unicorn/cdk/step03_graphQl/node_modules/@aws-cdk/core/lib/duration").Duration) => boolean' is not assignable to type '(t: import("D:/Unicorn/cdk/step03_graphQl/node_modules/@aws-cdk/aws-appsync/node_modules/@aws-cdk/core/lib/duration").Duration) => boolean'.
      Types of parameters 't' and 't' are incompatible.
        Type 'import("D:/Unicorn/cdk/step03_graphQl/node_modules/@aws-cdk/aws-appsync/node_modules/@aws-cdk/core/lib/duration").Duration' is not assignable to type 'import("D:/Unicorn/cdk/step03_graphQl/node_modules/@aws-cdk/core/lib/duration").Duration'.
          Types have separate declarations of a private property 'amount'.

17             expires: cdk.Expiration.after(cdk.Duration.days(365)), ///set expiration for API Key
               ~~~~~~~

lib/step03_graph_ql-stack.ts:39:7 - error TS2741: Property 'minus' is missing in type 'import("D:/Unicorn/cdk/step03_graphQl/node_modules/@aws-cdk/core/lib/duration").Duration' but required in type 'import("D:/Unicorn/cdk/step03_graphQl/node_modules/@aws-cdk/aws-appsync/node_modules/@aws-cdk/core/lib/duration").Duration'.

39       timeout: cdk.Duration.seconds(10), ///Time for function to break. limit upto 15 mins
         ~~~~~~~

  node_modules/@aws-cdk/aws-appsync/node_modules/@aws-cdk/core/lib/duration.d.ts:63:5
    63     minus(rhs: Duration): Duration;
           ~~~~~
    'minus' is declared here.
  node_modules/@aws-cdk/aws-lambda/lib/function.d.ts:59:14
    59     readonly timeout?: Duration;
                    ~~~~~~~
    The expected type comes from property 'timeout' which is declared here on type 'FunctionProps'
Found 2 errors.

将包更新为相同版本的

代码语言:javascript
复制
"dependencies": {
    "@aws-cdk/aws-appsync": "^1.121.0",
    "@aws-cdk/aws-lambda": "^1.121.0",
    "@aws-cdk/core": "1.121.0",
    "source-map-support": "^0.5.16"
  }
EN

回答 1

Stack Overflow用户

发布于 2022-04-18 19:26:39

确保

package.json

  • have中,
  • 中的@aws-cdk/core@aws-cdk/aws-appsync@aws-cdk/aws-lambda与您的开发环境中的cdk具有相同的版本,与您在项目中定义的包相同或更高。(全局npm高于或等于您的项目)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71915505

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档