aws / aws/jsii

If you use Construct as an interface, it gives an error in the Construct code rather than your code

Open
#4,004 2 comments 0 reactions 0 assignees View on GitHub
bug documentation language/dotnet language/java module/compiler needs-reproduction p1
Dominant language
TypeScript
Stars
2.9k
Forks
267
Avg merge
1d 25m
Merged PRs (30d)
14

Description

### Describe the bug

In a codebase I'm working on, I incorrectly implemented an interface that extends `Construct`. Since `Construct` is not an interface, this is a problem. However, the error that I got[1] gave me an error in the `@aws-cdk/core` codebase, _not_ in my code where I did the thing.

[1]
```
../../node_modules/@aws-cdk/core/lib/construct-compat.d.ts:50:1 - error JSII3005: Type "@aws-cdk/core.Construct" cannot be used as an interface

50 export declare class Construct extends constructs.Construct implements IConstruct {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51 /**
~~~~~~~
...
117 protected synthesize(session: ISynthesisSession): void;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
118 }
~
```

### Expected Behavior

I would expect to see an error that shows where in my code I did the wrong thing.

### Current Behavior

It shows an error somewhere in the CDK codebase, which is both unhelpful and confusing.

### Reproduction Steps

Define an interface that extends `Construct`.

### Possible Solution

_No response_

### Additional Information/Context

_No response_

### SDK version used

jsii 1.176.0

### Environment details (OS name and version, etc.)

macOS 12.6.3

Contributor guide

Open the contributing guide

Research direction

Reproduce the case by defining an interface that extends Construct, using the reported jsii 1.176.0 setup. Start by tracing the diagnostic reported at node_modules/@aws-cdk/core/lib/construct-compat.d.ts:50 and compare it with the user's interface location; done means the error points to the incorrect declaration in the user's code.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers, developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.