-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when types are imported but seemingly unused in Go #3399
Comments
Ran into this same problem. Just another example of it: import * as rds from "aws-cdk-lib/aws-rds";
export interface MyProps {
readonly database: rds.ServerlessCluster | rds.DatabaseCluster | rds.DatabaseInstance;
} It compiles to this in Go: import (
"github.com/aws/aws-cdk-go/awscdk/v2/awsrds"
)
type MyProps struct {
Database interface{} `field:"required" json:"database" yaml:"database"`
} And the |
Yeah seems like a code generator bug around type unions, as those end up being represented as A workaround would be to actually expose a type from the library outside of the context of a type union... Obviously this means exposing an undesired API... so it's not ideal. I'm going to look into addressing this in the next couple of days.... hopefully we can release a fix soon. |
Awesome, thanks! Looks like goimports could also cleanup imports. It's installed separately though. |
When imported types are solely referenced by type unions, a go import is emitted, but is never used (type unions end up represented as opaque `interface{}` type). This causes compilation failures. Added a test case for this scenario in particular, and adjusted go code generation to not emit dependency imports for type unions. These imports may be re-introduced soon, as we are working to add dynamic type checking around type unions in go (at which point those imports would no longer be unused). Fixes #3399
@polothy yeah I'm aware of I've pushed out a PR with a fix for the particular issue experienced here. The fix turned out to be trivial. As noted on the PR comments, we are working to add dynamic/runtime type checking around type union locations in the go code (#3641), which is going to make those imports be actually useful in the future... Hopefully soon 🙃 |
When imported types are solely referenced by type unions, a go import is emitted, but is never used (type unions end up represented as opaque `interface{}` type). This causes compilation failures. Added a test case for this scenario in particular, and adjusted go code generation to not emit dependency imports for type unions. These imports may be re-introduced soon, as we are working to add dynamic type checking around type unions in go (at which point those imports would no longer be unused). Fixes #3399
|
🐛 Bug Report
Affected Languages
TypeScript
orJavascript
Python
Java
C#
,F#
, ...)Go
General Information
jsii/superchain:1-buster-slim
imageWhat is the problem?
This is in relation to https://github.com/cdklabs/cdk-monitoring-constructs
Given some code that looks like:
Go build fails with the following:
(See failed build)
We also attempted importing the type only, i.e.:
(See failed build)
I also attempted to reduce the codebase down to just the above for a minimum repo, but ended up with errors like:
Verbose Log
I unfortunately can't seem to do a build locally due to network policies. Let me know if I can somehow provide more info otherwise.
The text was updated successfully, but these errors were encountered: