aws / aws/jsii

Ability to force an interface to be considered as a struct

Open
#2,267 0 comments 2 reactions 0 assignees View on GitHub
effort/small feature-request module/compiler p1
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#`, ...)

### General Information

Sometimes, a struct's "natural" name could start with a capital letter `i` followed by another capital letter. This in fact happens in several instances in the `aws-cdk` (`IAMThis`, `IPThat`, ...). This is particularly challenging to work around in cases where code is generated, as it may not always be obvious how to case-adjust those names to avoid the `I[A-Z]` prefix.

Unfortunately, `jsii` will consider any interface named with an `I[A-Z]` prefix as a behavioral interface, which significantly degrades the user experience around those types. This proposal is to add an optional `@struct` TSDoc annotation that will "force" a particular interface to be interpreted as a struct, regardless of it's name (it will still be required to be a valid struct, meaning it cannot declare any method and must have only `readonly` properties).

This would be the most elegant solution to aws/aws-cdk#11501.

Contributor guide

Open the contributing guide

Research direction

The issue names no files, tests, or entry points. Start by locating jsii's interface classification and TSDoc annotation handling, then trace how struct validity is checked; done means a valid readonly, method-free interface with an I[A-Z] name can opt into struct treatment through @struct, with coverage for the annotation and invalid cases.

Written by the indexing model from the issue text.

Assessment

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