Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update helper class build functions to return explicit interface types instead of anonymous values in an array #853

Closed
1 of 2 tasks
georgebearden opened this issue Nov 28, 2022 · 0 comments · Fixed by #904
Labels
feature-request A feature should be added or improved needs-triage The issue or PR still needs to be triaged

Comments

@georgebearden
Copy link
Contributor

While working on a new construct in #849, it was mentioned that we should consider defining explicit interfaces for the return values of the build functions from our helper classes. See here for an example.

Use Case

By defining explicit interface types as the return values for the helper class build functions, we can improve the usability of the APIs. This will help consumers of the helper classes by using actual strongly-typed property names, and not have to index into arrays.

Proposed Solution

Change the helper classes build methods from this (using sns-helper as an example):

export function buildTopic(scope: Construct, props: BuildTopicProps): [sns.Topic, kms.Key?] {
  if (!props.existingTopicObj) {  
   ...
    return [topic, snsTopicProps.masterKey];
  } else {
    return [props.existingTopicObj];
  }
}

to this:

export interface BuildTopicResult {
  readonly topic: sns.Topic;
  readonly encryptionKey?: kms.Key;
}

export function buildTopic(scope: Construct, props: BuildTopicProps): BuildTopicResult {
  if (!props.existingTopicObj) {  
   ...
    return {
      topic, 
      encryptionKey: snsTopicProps.masterKey
    }
  } else {
    return {
      topic
    }
  }
}

Other

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A feature should be added or improved needs-triage The issue or PR still needs to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant