首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Typescript错误:无法为类型(相同类型不同文件夹)的参数赋值

Typescript错误:无法为类型(相同类型不同文件夹)的参数赋值
EN

Stack Overflow用户
提问于 2021-09-10 14:44:08
回答 1查看 413关注 0票数 1

我目前正在开发aws cdk,我正在使用Typescript进行设置。我有一个问题,我有相同的库,但它们被引用为不同的类型。

编译错误:

代码语言:javascript
复制
Argument of type 'import("/Users/Smit/Documents/Dev/aws-cdk/cdk-cloud-formation-appreciation-dashboard/node_modules/@aws-cdk/core/lib/cfn-output").CfnOutput' is not assignable to parameter of type 'import("/Users/Smit/Documents/Dev/aws-cdk/cdk-cloud-formation-appreciation-dashboard/node_modules/@aws-cdk/aws-codestarnotifications/node_modules/@aws-cdk/core/lib/cfn-output").CfnOutput'.
  Types have separate declarations of a private property '_description'.
代码语言:javascript
复制
Argument of type 'CdkCloudFormationAppreciationDashboardStage' is not assignable to parameter of type 'Stage'.
  Types of property '_assemblyBuilder' are incompatible.
    Type 'import("/Users/Smit/Documents/Dev/aws-cdk/cdk-cloud-formation-appreciation-dashboard/node_modules/@aws-cdk/cx-api/lib/cloud-assembly").CloudAssemblyBuilder' is not assignable to type 'import("/Users/Smit/Documents/Dev/aws-cdk/cdk-cloud-formation-appreciation-dashboard/node_modules/@aws-cdk/aws-codestarnotifications/node_modules/@aws-cdk/cx-api/lib/cloud-assembly").CloudAssemblyBuilder'.
      Types have separate declarations of a private property 'artifacts'.ts(2345)

代码:

代码语言:javascript
复制
 // This is where we add the application stages
   const preprod = new CdkCloudFormationAppreciationDashboardStage(this, 'PreProd', {
    env: { account: 'accountnumber', region: 'ap-southeast-1' },
  });

  // put validations for the stages 
  const preprodStage = pipeline.addApplicationStage(preprod);

Package.json

代码语言:javascript
复制
"dependencies": {
    "@aws-cdk/aws-apigateway": "^1.122.0",
    "@aws-cdk/aws-codepipeline": "^1.122.0",
    "@aws-cdk/aws-codepipeline-actions": "^1.122.0",
    "@aws-cdk/aws-dynamodb": "^1.122.0",
    "@aws-cdk/aws-lambda": "^1.122.0",
    "@aws-cdk/core": "1.121.0",
    "@aws-cdk/pipelines": "^1.122.0",
    "@types/aws-lambda": "^8.10.83",
    "source-map-support": "^0.5.16"
  }

完整日志:

代码语言:javascript
复制
> cdk-cloud-formation-appreciation-dashboard@0.1.0 build
> tsc

lib/cdk-cloud-formation-appreciation-dashboard-pipeline.ts:40:9 - error TS2322: Type 'import("/Users/Smit/Documents/Dev/aws-cdk/cdk-cloud-formation-appreciation-dashboard/node_modules/@aws-cdk/core/lib/secret-value").SecretValue' is not assignable to type 'import("/Users/Smit/Documents/Dev/aws-cdk/cdk-cloud-formation-appreciation-dashboard/node_modules/@aws-cdk/aws-codestarnotifications/node_modules/@aws-cdk/core/lib/secret-value").SecretValue'.
  Types have separate declarations of a private property 'value'.

40         oauthToken: SecretValue.secretsManager('devhour-backend-git-access-token', {jsonField: 'devhour-backend-git-access-token'}), // this token is stored in Secret Manager
           ~~~~~~~~~~

  node_modules/@aws-cdk/aws-codepipeline-actions/lib/github/source-action.d.ts:118:14
    118     readonly oauthToken: SecretValue;
                     ~~~~~~~~~~
    The expected type comes from property 'oauthToken' which is declared here on type 'GitHubSourceActionProps'

lib/cdk-cloud-formation-appreciation-dashboard-pipeline.ts:61:53 - error TS2345: Argument of type 'CdkCloudFormationAppreciationDashboardStage' is not assignable to parameter of type 'Stage'.
  Types of property '_assemblyBuilder' are incompatible.
    Type 'import("/Users/Smit/Documents/Dev/aws-cdk/cdk-cloud-formation-appreciation-dashboard/node_modules/@aws-cdk/cx-api/lib/cloud-assembly").CloudAssemblyBuilder' is not assignable to type 'import("/Users/Smit/Documents/Dev/aws-cdk/cdk-cloud-formation-appreciation-dashboard/node_modules/@aws-cdk/aws-codestarnotifications/node_modules/@aws-cdk/cx-api/lib/cloud-assembly").CloudAssemblyBuilder'.
      Types have separate declarations of a private property 'artifacts'.

61   const preprodStage = pipeline.addApplicationStage(preprod);
                                                       ~~~~~~~

lib/cdk-cloud-formation-appreciation-dashboard-pipeline.ts:68:42 - error TS2345: Argument of type 'import("/Users/Smit/Documents/Dev/aws-cdk/cdk-cloud-formation-appreciation-dashboard/node_modules/@aws-cdk/core/lib/cfn-output").CfnOutput' is not assignable to parameter of type 'import("/Users/Smit/Documents/Dev/aws-cdk/cdk-cloud-formation-appreciation-dashboard/node_modules/@aws-cdk/aws-codestarnotifications/node_modules/@aws-cdk/core/lib/cfn-output").CfnOutput'.
  Types have separate declarations of a private property '_description'.

68       ENDPOINT_URL: pipeline.stackOutput(preprod.urlOutput),
                                            ~~~~~~~~~~~~~~~~~
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-09-10 15:09:37

您需要确保Aws-cdk包都是相同的版本。

将它们都设置为1.122.0,不要使用^。这不是一个好的实践,在cdk中事情经常会发生变化。

代码语言:javascript
复制
"dependencies": {
    "@aws-cdk/aws-apigateway": "1.122.0",
    "@aws-cdk/aws-codepipeline": "1.122.0",
    "@aws-cdk/aws-codepipeline-actions": "1.122.0",
    "@aws-cdk/aws-dynamodb": "1.122.0",
    "@aws-cdk/aws-lambda": "1.122.0",
    "@aws-cdk/core": "1.122.0",
    "@aws-cdk/pipelines": "1.122.0",
    "@types/aws-lambda": "^8.10.83",
    "source-map-support": "^0.5.16"
  }
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69133980

复制
相关文章

相似问题

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