aws / aws/jsii

Support arbitrary additional fields as map or dictionary type

Open
#2,928 1 comment 2 reactions 1 assignee Claimed by @RomainMuller View on GitHub
feature-request module/jsii p1
Dominant language
TypeScript
Stars
2.9k
Forks
267
Avg merge
1d 25m
Merged PRs (30d)
14

Description

## :rocket: Feature Request

### Affected Languages

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

### General Information
* **JSII Version:**
* **Platform:**

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

* [ ] This feature might incur a breaking change

### Description

By default, empty interfaces in TypeScript allow adding any arbitrary properties. In addition, it is possible to allow arbitrary properties in interfaces with existing fields through [index signatures](https://www.typescriptlang.org/docs/handbook/interfaces.html#indexable-types):

```typescript
export interface Foo {
readonly myRequiredProp: string;
readonly myOptionalProp?: string;
readonly [key: string]: any;
}
```

Currently, neither method of supporting arbitrary fields are transliterated to Python (or other languages AFAIK). So if the interface is empty, than no properties can be added in the constructor (even though it's possible in TypeScript). This limitation came up in https://github.com/cdk8s-team/cdk8s-cli/issues/33.

### Proposed Solution

In Python, these interfaces should probably be transliterated into parameters with the [`**kwargs` syntax](https://book.pythontips.com/en/latest/args_and_kwargs.html). For other languages, I'm not sure if there are as clean equivalents. For example in Java, it might be necessary to have some reserved keyword for use in interfaces like `extraFields` which is simply typed as a mapping from strings to objects.

This obviously presents some questions about runtime and type safety, so if that is an issue, or the feature isn't feasible for other technical reasons, perhaps it's worth adding some kind of optional validation as part of jsii that checks that index signatures are used in publicly exported interfaces? This part I'm not as sure about.

---

If this feature/issue has already been reported somewhere please let me know!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.