aws / aws/jsii

Add support for `Omit` and `Partial` types to aid in extending Props interfaces

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

Description

### Describe the feature

I'd like to be able to use `Omit` and `Partial` to create a sub-set of a Construct class I am sub-classing.

### Use Case

I regularly extend L2 Constructs with opinionated (and more importantly, narrower) interfaces. For example, a L3 may require the underlying DB be Postgres and doesn't allow the `engine` to be set. But, I still want to expose the rest of `rds.ServerlessClusterProps` as optional props to be configured. Doing this today requires redundant copy/pasting of the props interfaces into the L3 Constructs which is wasteful and annoying in cases where the interfaces have deep hierarchies.

This should be possible:
```ts
export interface MyServiceProps extends Omit {}

// or also make all the props optional
export interface MyServiceProps extends Partial> {}
```

### Proposed Solution

JSII can leverage the type checker to resolve the properties on the omitted type and emit a new class that is a subset.

### Other Information

_No response_

### Acknowledgements

- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change

### CDK version used

2.126.0

### Environment details (OS name and version, etc.)

MacOS 14.1

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the jsii type checker and how it resolves and emits interface properties across languages. Use the Omit and Partial examples in the issue to define the expected subset and optionality behavior, then verify that the generated cross-language types preserve those semantics.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers, developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.