awslabs / aws-bootstrap-kit

Apache License 2.0
105 stars 22 forks source link

Argument of type 'this' is not assignable to parameter of type 'Construct'. #102

Closed moltar closed 2 years ago

moltar commented 2 years ago

It looks like the constructs packages is outdated and I am getting the type conflicts with the latest version.

My project:

    "constructs": "10.1.28",

Argument of type 'this' is not assignable to parameter of type 'Construct'.

Argument of type 'this' is not assignable to parameter of type 'Construct'.
  Type 'AWSBootstrapKitLandingZoneStage' is not assignable to type 'Construct'.
    Types of property 'node' are incompatible.
      Type 'import(".../node_modules/constructs/lib/construct").Node' is not assignable to type 'import(".../node_modules/aws-bootstrap-kit/node_modules/constructs/lib/construct").Node'.
        Types have separate declarations of a private property 'host'.
flochaz commented 2 years ago

That is weird, you should be able to use whatever version since we added ^ in peer deps: https://github.com/awslabs/aws-bootstrap-kit/pull/77/files

moltar commented 2 years ago

Yeah, I thought that was odd as well.

moltar commented 2 years ago

Wait, the dependencies value is still fixed though!

https://github.com/awslabs/aws-bootstrap-kit/blob/cfaf3f699bb76d29d31311b2f72307866352a92e/source/aws-bootstrap-kit/package.json#L58-L65

flochaz commented 2 years ago

You can solve this by adding the following block to your package.json :

"overrides": {
      "aws-bootstrap-kit": {
        "aws-cdk-lib": "2.27.0",
        "constructs": "10.1.31"
      }
    }

and make sure to pin prettier types in your dev deps (https://github.com/aws/aws-cdk/issues/20319)

"@types/prettier": "2.6.0"
moltar commented 2 years ago

Ok, this worked. But this requires npm@8. This may not affect many people, but still good to know.

Another pro tip, it is possible to use references to the package versions you already have installed:

  "overrides": {
    "aws-cdk-lib": "$aws-cdk-lib",
    "constructs": "$constructs"
  }