aws / aws/jsii

Improve error messaging around undefined and null types

Open
#3,224 0 comments 3 reactions 0 assignees View on GitHub
feature-request module/jsii p2
Dominant language
TypeScript
Stars
2.9k
Forks
267
Avg merge
1d 25m
Merged PRs (30d)
14

Description

## :rocket: Feature Request

### Affected Languages

- [x] `TypeScript` or `Javascript`
- [ ] `Python`
- [ ] `Java`
- [ ] .NET (`C#`, `F#`, ...)
- [ ] `Go`

### General Information
* **JSII Version:** 1.46.0
* **Platform:** macOS 11.6.1

* [x] I may be able to implement this feature request

* [ ] This feature might incur a breaking change

### Description

Currently, if you try adding `| null` to an optional type in a JSII library, it gives a cryptic error message:

```
[2021-12-02T14:51:19.767] [ERROR] jsii/compiler - Type model errors prevented the JSII assembly from being created
src/awscdk-app-ts.ts:40:12 - error JSII1001: Non-primitive types without a symbol cannot be processed.

40 readonly appEntrypoint?: string | null;
```

JSII target languages do not support distinguishing between `null` and `undefined`, so I think it makes sense for this to be disallowed - but the error message doesn't allude to this.

### Proposed Solution

Change the diagnostics logic to give a more specific error message for this kind of error.

Contributor guide

Open the contributing guide

Research direction

Start by locating the JSII compiler diagnostics logic that reports JSII1001 for an optional TypeScript type containing null. Reproduce the example with `readonly appEntrypoint?: string | null` and make the diagnostic explain that target languages cannot distinguish null from undefined; the existing compiler checks should continue to reject it.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 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.