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

feat: IDE type navigation assistance for command classes #1373

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

kuhe
Copy link
Contributor

@kuhe kuhe commented Aug 21, 2024

closes #1366

This PR creates declare protected static fields on classes pointing to commonly sought after associated type declarations.

This is needed because the type declaration position of commands can be distant from the type declaration of the operation's input and output.

In the future, the list of modeled Exception classes could also be listed here.

Reasoning

  • declare this allows the field to have a type annotation without assigning any runtime value. In the runtime JavaScript code, these types do not appear at all. This avoids wasting runtime artifact size on what is essentially documentation.
  • static avoids autocomplete proposing this field on instances of the Command class.
  • protected avoids autocomplete proposing this field on the Command class constructor.

Source code

export class ListBucketsCommand extends $Command
  .classBuilder<
    ListBucketsCommandInput,
    ListBucketsCommandOutput,
    S3ClientResolvedConfig,
    ServiceInputTypes,
    ServiceOutputTypes
  >()
  .ep({
    ...commonParams,
  })
  .m(function (this: any, Command: any, cs: any, config: S3ClientResolvedConfig, o: any) {
    return [
      getSerdePlugin(config, this.serialize, this.deserialize),
      getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
      getThrow200ExceptionsPlugin(config),
    ];
  })
  .s("AmazonS3", "ListBuckets", {})
  .n("S3Client", "ListBucketsCommand")
  .f(void 0, void 0)
  .ser(se_ListBucketsCommand)
  .de(de_ListBucketsCommand)
  .build() {
  /** @internal type navigation helper, not in runtime. */
  protected declare static inputTypeRef: [ListBucketsCommandInput, ListBucketsRequest];
  /** @internal type navigation helper, not in runtime. */
  protected declare static outputTypeRef: [ListBucketsCommandOutput, ListBucketsOutput];
}

.d.ts dist-types

Type references now appear very close to the Command type declaration for easier navigation.

export declare class ListBucketsCommand extends ListBucketsCommand_base {
    /** @internal type navigation helper, not in runtime. */
    protected static inputTypeRef: [ListBucketsCommandInput, ListBucketsRequest];
    /** @internal type navigation helper, not in runtime. */
    protected static outputTypeRef: [ListBucketsCommandOutput, ListBucketsOutput];
}

.js dist-es

Invisible to the runtime.

export class ListBucketsCommand extends $Command
  .classBuilder()
  .ep({
    ...commonParams,
  })
  .m(function (Command, cs, config, o) {
    return [
      getSerdePlugin(config, this.serialize, this.deserialize),
      getEndpointPlugin(config, Command.getEndpointParameterInstructions()),
      getThrow200ExceptionsPlugin(config),
    ];
  })
  .s("AmazonS3", "ListBuckets", {})
  .n("S3Client", "ListBucketsCommand")
  .f(void 0, void 0)
  .ser(se_ListBucketsCommand)
  .de(de_ListBucketsCommand)
  .build() {}

@kuhe kuhe requested review from a team as code owners August 21, 2024 18:57
@kuhe kuhe merged commit 5306c73 into smithy-lang:main Sep 13, 2024
11 checks passed
@kuhe kuhe deleted the feat/command-io-types branch September 13, 2024 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Navigating to input and output types for a command in TypeScript is too tedious
4 participants