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!
[ ] 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:
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!
:rocket: Feature Request
Affected Languages
TypeScript
orJavascript
Python
Java
C#
,F#
, ...)Go
General Information
jsii --version
-->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:
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 likeextraFields
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!