Typescript错误:不能赋值给类型(相同类型不同文件夹)的参数



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

编译错误:

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'.
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)
代码:

// 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

"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"
}

完整日志:

> 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),
~~~~~~~~~~~~~~~~~

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

将它们全部设置为1.122.0,不要使用^。这不是一个好的做法,在cdk中情况经常变化。

"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"
}

相关内容

  • 没有找到相关文章

最新更新