jetbridge / cdk-nextjs

Deploy a NextJS application using AWS CDK
https://constructs.dev/packages/cdk-nextjs-standalone
Apache License 2.0
274 stars 46 forks source link

Missing types for `defaults` #55

Closed revmischa closed 11 months ago

revmischa commented 1 year ago

Right now defaults.distribution and defaults.assetDeployment are any This is a limitation in jsii we need to figure out a workaround for I want the type to be e.g. Partial<DistributionProps> but we can't use Partial<> in jsii

See this thread on the CDK slack for more details: https://cdk-dev.slack.com/archives/C01C8R4K2E6/p1665107002345799

khuezy commented 1 year ago

Man, jsii is a big headache.

jadenv commented 1 year ago

@revmischa looks like this commit removed the any discussed here in v2.0.5.

We were using the distribution to set custom domain thing and some other properties, but now this complains that not all the other properties are implemented. We do not want to implement all of them, just some.

new Nextjs(this, "NextLambdaEdge", {
  nextjsPath: "../next",
  projectRoot: "..",

  defaults: {
    distribution: {
      customDomain: {
        domainName: props.reactDomainName,
        hostedZone: HostedZone.fromHostedZoneAttributes(this, "HostedZone", <HostedZoneAttributes>{
          hostedZoneId: props.hostedZoneId,
          zoneName: props.zoneName
        }),
        certificate: Certificate.fromCertificateArn(this, "Certificate", props.certificateArn)
      },

      cdk: {
        distribution: { webAclId: props.webAclId }
      }
    }
  }
});

What is the correct approach now that the any was removed?

revmischa commented 1 year ago

Ok I see now that this causes a type error in 2.0.5. I will revert the change. I just don't know how to get around this jsii limitation. The correct type should be Partial<NextjsDistributionProps> but jsii won't permit you to use Partial<> because it isn't cross-language compatible. I was hoping any | NextjsDistributionProps would allow you to pass whatever but still give you code hinting, but perhaps not.

bestickley commented 11 months ago

It's not possible to use Partial<> with JSII :(. Closing.