'Getting aws-cdk errors in typescript

How to resolve these errors in typescript I have created this with cdk innit app --language typescript. Vscode underlines timeout and expires properties in config.

My constructors in lib folders are

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",
    });
  }
}

on running tsc i get these errors.

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.

updated packages to same version

"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"
  }


Solution 1:[1]

Make sure

  • have the @aws-cdk/core, @aws-cdk/aws-appsync, @aws-cdk/aws-lambda the same version in the package.json
  • have your cdk in your development environment relase which is equal or higher then you packages defined in your project. (global npm cdk is higher or equal than in your project)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sándor Bakos