Typescript TS2345:type';构建';不是派生自';构建';
以下是本页上的教程: 我相信传递给Typescript TS2345:type';构建';不是派生自';构建';,typescript,Typescript,以下是本页上的教程: 我相信传递给表构造函数的这个应该是HitCounter,是cdk.Construct的子构造函数 它返回这个lint: 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 prot
表构造函数的这个应该是HitCounter
,是cdk.Construct的子构造函数
它返回这个lint:
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)
在这一步中,我还遇到了一个内部服务器错误。有人知道问题是什么吗
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>
}
}
import*作为cdk从“@aws cdk/core”导入;
从“@aws cdk/aws lambda”导入*作为lambda;
从“@aws cdk/aws dynamodb”导入*作为dynamodb;
导出接口HITProps{下游:lambda.iffunction;}
导出类HitCounter扩展了cdk.Construct{
公共只读处理程序:lambda.Function;
构造函数(作用域:cdk.Construct,id:string,props:hitcrops){
超级(范围,id);
const table=new dynamodb.table(这个“Hits”,{//lints`this`
分区键:{
名称:“路径”,
类型:dynamodb.AttributeType.STRING
}
});
}
}
我也有同样的问题。您必须将所有不同的cdk软件包设置为同一版本,请参阅
将cd复制到项目路径
运行:npx npm检查更新-u
运行:npm安装
重新启动IDE
您可能不仅要取消node\u modules文件夹,还要取消package lock.json