首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TS2345:类型“构造”不是从“构造”派生出来的类

TS2345:类型“构造”不是从“构造”派生出来的类
EN

Stack Overflow用户
提问于 2020-04-22 03:53:22
回答 2查看 4.4K关注 0票数 5

以下是本页上的教程:https://cdkworkshop.com/20-typescript/40-hit-counter/300-resources.html

我认为传递给this构造函数的Table应该是HitCounter,它是cdk.Construct的一个子构造函数。

它返回这条皮棉:

代码语言:javascript
复制
this: this
Argument of type 'this' is not assignable to parameter of type 'Construct'.
  Type 'HitCounter' is not assignable to type 'Construct'.
    Property 'onValidate' is protected but type 'Construct' is not a class derived from 'Construct'.ts(2345)

在这个步骤中,我还会得到一个内部服务器错误。有人知道问题是什么吗?

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

export interface HitCounterProps { downstream : lambda.IFunction; }

export class HitCounter extends cdk.Construct {
   public readonly handler: lambda.Function;

   constructor(scope: cdk.Construct, id: string, props: HitCounterProps) {
      super(scope, id);

      const table = new dynamodb.Table(this, "Hits", { // lints `this`
         partitionKey : { 
            name : "path", 
            type : dynamodb.AttributeType.STRING 
         }
      });
      <more code removed>
   }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-04-28 16:41:17

我也有过同样的问题。您必须将所有不同的cdk包设置为相同的版本,请参见https://github.com/aws/aws-cdk/issues/542#issuecomment-449694450

票数 18
EN

Stack Overflow用户

发布于 2020-06-24 12:55:54

指向项目路径的npx npm-check-updates -u

  • run:npm install

  • restart

  • cd

  • 运行:
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61357033

复制
相关文章

相似问题

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