aws / aws/jsii

Method cannot return `Promise<string | undefined>`

Open
#4,035 0 comments 1 reaction 0 assignees View on GitHub
bug p2
Dominant language
TypeScript
Stars
2.9k
Forks
267
Avg merge
1d 25m
Merged PRs (30d)
14

Description

### Describe the bug

When I try to write an interface, a method can return a promise of a plain type, or return an optional type (some type unioned with `null`/`undefined`, but it can't return a promise of an optional type.

```ts
interface IStuff
foo(): string | undefined; // OK

bar(): Promise; // OK

baz(): Promise; // ERROR
}
```

### Expected Behavior

Successful compile

### Current Behavior

Compiler error

### Reproduction Steps

See snippet above

### Possible Solution

I think on these lines:
https://github.com/aws/jsii/blob/b459b1d71f3bc91f0aa634d233a415250105c600/packages/jsii/lib/assembler.ts#L2532-L2538

it could be changed to instead return:

```ts
return this._optionalValue(typeRef.typeArguments[0], declaration, purpose);
```

### Additional Information/Context

I haven't been able to test if this will work in Python / Java / Go etc

### SDK version used

1.74.0

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

macOS

Contributor guide

Open the contributing guide

Research direction

Start in packages/jsii/lib/assembler.ts at lines 2532-2538 and reproduce the interface example from the issue. Trace how the Promise type argument is classified, then verify that the example compiles and that the behavior remains valid for Python, Java, and Go.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.