Typescript 类型为'的参数;这';不可分配给类型为';构建';
即使我有相同版本的cdk依赖项,我也很难弄清楚这里的问题是什么。Typescript 类型为'的参数;这';不可分配给类型为';构建';,typescript,amazon-web-services,aws-cdk,Typescript,Amazon Web Services,Aws Cdk,即使我有相同版本的cdk依赖项,我也很难弄清楚这里的问题是什么。 const identityPool=new cognito.cfnidentipool(这是“identityPool”,{ Argument of type 'this' is not assignable to parameter of type 'Construct'. Type 'MyStack' is not assignable to type 'Construct'. Types of property
const identityPool=new cognito.cfnidentipool(这是“identityPool”,{
Argument of type 'this' is not assignable to parameter of type 'Construct'.
Type 'MyStack' is not assignable to type 'Construct'.
Types of property 'node' are incompatible.
Type 'import("(**/node_modules/@aws-cdk/core/lib/construct-compat").ConstructNode' is not assignable to type 'import("**/node_modules/@aws-cdk/aws-appsync/node_modules/@aws-cdk/core/lib/construct-compat").ConstructNode'.
Types have separate declarations of a private property 'host'.ts(2345)
复制步骤
环境
- **CDK CLI版本:1.106.1
- Node.js版本:v16.2.0
- **操作系统:Ubuntu
- 语言(版本):打字脚本(4.3.2)
@aws cdk/core
库。首先确保这是问题所在:
纱线为什么@aws cdk/芯
#或
npm为什么@aws cdk/核心
将向您显示项目中安装的所有版本的@aws cdk/core
,以及使用这些版本的软件包。如果存在多个版本,请使用通用拼写:
rm-射频节点\u模块
rm.lock
纱线安装
#或
rm package-lock.json
npm安装
如果这仍然没有帮助,并且仍然有两个版本的软件包用于强制执行单一版本的解析。请在文件顶部包含导入语句。根据这一行,看起来您在那里遇到了一些问题:
Type'import(***/node\u modules/@aws cdk/core/lib/construct compat”).ConstructNode“不可分配给类型”import(***/node\u modules/@aws cdk/aws appsync/node\u modules/@aws cdk/core/lib/construct compat”)。ConstructNode“
第二个路径较长。我不这么认为。您是否尝试将最后一个导入作为第一个导入?也许typescript会首先查看该依赖关系?
"devDependencies": {
"@aws-cdk/assert": "1.106.0",
"@types/aws-lambda": "^8.10.76",
"@types/aws-sdk": "^2.7.0",
"@types/jest": "^26.0.10",
"@types/node": "^15.6.1",
"aws-cdk": "1.106.0",
"jest": "^26.4.2",
"ts-jest": "^26.2.0",
"ts-node": "^9.0.0",
"typescript": "~3.9.7"
},
"dependencies": {
"@aws-cdk/aws-appsync": "^1.106.0",
"@aws-cdk/aws-cognito": "^1.106.0",
"@aws-cdk/aws-dynamodb": "^1.106.0",
"@aws-cdk/aws-lambda": "^1.106.0",
"@aws-cdk/aws-s3": "^1.106.0",
"@aws-cdk/core": "1.106.0",
"graphql-scalars": "^1.9.3",
"source-map-support": "^0.5.16",
"yaml": "^1.10.2"
}
}
import * as appsync from "@aws-cdk/aws-appsync";
import * as cognito from "@aws-cdk/aws-cognito";
import * as ddb from '@aws-cdk/aws-dynamodb';
import * as iam from "@aws-cdk/aws-iam";
import * as lambda from '@aws-cdk/aws-lambda';
import * as s3 from "@aws-cdk/aws-s3";
import * as cdk from "@aws-cdk/core";
export class MyStack extends cdk.Stack {
private readonly stage: Stage;
private readonly context: string;
private namePrefix() {
return `${this.stage}-${this.context}`;
}
constructor(scope: cdk.Construct, id: string, props: MyStackProps) {
super(scope, id, props);
this.stage = props.stage;
this.context = props.context;
const userPool = new cognito.UserPool(
this,
this.namePrefix() + "-user-pool",
{
userPoolName: this.namePrefix() + "-user-pool",
selfSignUpEnabled: true,
removalPolicy: cdk.RemovalPolicy.DESTROY,
accountRecovery: cognito.AccountRecovery.PHONE_AND_EMAIL,
userVerification: {
emailStyle: cognito.VerificationEmailStyle.CODE,
},
autoVerify: {
email: true,
},
standardAttributes: {
email: {
required: true,
mutable: true,
},
},
}
);
const userPoolClient = userPool.addClient(
this.namePrefix() + "-user-pool-client",
{
userPoolClientName: this.namePrefix() + "-user-pool-client",
oAuth: {
flows: { authorizationCodeGrant: true, implicitCodeGrant : true },
scopes: [cognito.OAuthScope.PROFILE],
callbackUrls: ["http://localhost:4200/callback"],
},
authFlows : {
userPassword : true,
userSrp : true
},
supportedIdentityProviders: [
cognito.UserPoolClientIdentityProvider.COGNITO,
],
}
);
const identityPool = new cognito.CfnIdentityPool(this, "IdentityPool", {
allowUnauthenticatedIdentities: false, // Don't allow unathenticated users
cognitoIdentityProviders: [
{
clientId: userPoolClient.userPoolClientId,
providerName: userPool.userPoolProviderName,
},
],
});
}
}