aws / aws/jsii-compiler

interface A extends B fails if B is exported from a private file

Open
#2,082 0 comments 0 reactions 0 assignees View on GitHub
p2
Dominant language
TypeScript
Stars
50
Forks
26
Avg merge
7h 10m
Merged PRs (30d)
37

Description

The following succeeds:

```ts
export interface A extends B { /* ... */ }

interface B { /* ... */ }
```

It will "hide" the interface B entirely from jsii.

But the following fails:

```ts
import { B } from './private/b';

export interface A extends B { /* ... */ }
```

With the error "can't find B, make sure it's exported".

Even though it's the exact same situation.

```
aws-cloudwatch/lib/alarm.ts:33:1 - error JSII9002: Unable to resolve type "aws-cdk-lib.CreateAlarmOptionsBase". It may be @internal or not exported from the module's entry point (as configured in "package.json" as "main").
```

Adding `@internal` to `B` does appease jsii, but this still shouldn't happen this way.

## Probable reason

I'm guessing that the code that checks whether or not the `B` type should be hidden or should be visible looks at the `export` keyword and nothing else, but it `B` *must* have `export` if it comes from a different file, even if that file is itself not exported on purpose.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the two interface examples and inspect the type-export visibility logic that reports JSII9002, using aws-cloudwatch/lib/alarm.ts:33:1 as the failing example. Add a regression test showing that an exported interface extending a type exported from a private file is treated like one extending a local non-exported type; done means the imported case compiles without requiring @internal.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.