首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >类型“this”的参数不能分配给“结构”类型的参数

类型“this”的参数不能分配给“结构”类型的参数
EN

Stack Overflow用户
提问于 2021-06-01 12:43:42
回答 1查看 1.3K关注 0票数 1

即使我有相同版本的cdk依赖项,我也很难弄清楚这里的问题是什么。const identityPool = new cognito.CfnIdentityPool(this, "IdentityPool", {

代码语言:javascript
复制
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)
代码语言:javascript
复制
"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"
  }
}

复制步骤

代码语言:javascript
复制
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,
        },
      ],
    });
    
  }
 }

环境

  • **CDK CLI版本: 1.106.1
  • Node.js版本: v16.2.0
  • **OS : Ubuntu
  • 语言(版本):打字本(4.3.2)
EN

回答 1

Stack Overflow用户

发布于 2021-06-01 21:04:29

看起来您有两个不同版本的@aws-cdk/core库。首先,确保这是问题所在:

代码语言:javascript
复制
yarn why @aws-cdk/core
# or
npm why @aws-cdk/core

将向您展示安装在项目中的所有版本的@aws-cdk/core以及使用它们的包。如果当前有多个版本,请使用常见的咒语:

代码语言:javascript
复制
rm -rf node_modules

rm yarn.lock
yarn install
# or
rm package-lock.json
npm install

如果这仍然没有帮助,而且该包仍然有两个版本,那么使用纱线分辨率强制执行单个版本的解析。

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

https://stackoverflow.com/questions/67789102

复制
相关文章

相似问题

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