aws / jsii

jsii allows code in any language to naturally interact with JavaScript classes. It is the technology that enables the AWS Cloud Development Kit to deliver polyglot libraries from a single codebase!
https://aws.github.io/jsii
Apache License 2.0
2.65k stars 245 forks source link

Support arbitrary additional fields as map or dictionary type #2928

Open Chriscbr opened 3 years ago

Chriscbr commented 3 years ago

:rocket: Feature Request

Affected Languages

General Information

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:

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. 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!

henrysachs commented 1 year ago

i'm not sure about this one. Its P1 but for now more than 2 Years. Is there some movement in that area? I tripped about it just today again :(