Back to all reviewers

Accurate type signatures

aws/aws-sdk-js
Based on 2 comments
TypeScript

When defining API interfaces in TypeScript, ensure that method signatures accurately reflect the actual behavior and requirements of the implementation. Pay special attention to:

API TypeScript

Reviewer Prompt

When defining API interfaces in TypeScript, ensure that method signatures accurately reflect the actual behavior and requirements of the implementation. Pay special attention to:

  1. Parameter optionality: Consider carefully whether parameters should be optional (param?:) or required based on their usage patterns. If a callback is expected to be called in most use cases, it might be better to make it required to guide developers toward correct usage.

  2. Promise return types: Methods that return promises must specify the correct type of the resolved value. Never use Promise<void> when the promise actually resolves to a useful value.

Example of correcting return type:

// Incorrect
getSignedUrlPromise(operation: string, params: any): Promise<void>;

// Correct 
getSignedUrlPromise(operation: string, params: any): Promise<string>;

Example of parameter optionality consideration:

// With optional callback - allows but doesn't enforce callback usage
on(event: "validate", listener: (request: Request<D, E>, doneCallback?: () => void) => void): Request<D, E>;

// With required callback - enforces callback usage for correct implementation
on(event: "validate", listener: (request: Request<D, E>, doneCallback: () => void) => void): Request<D, E>;

Accurate type signatures improve API usability, enable better IDE support, and reduce runtime errors by catching incorrect usage patterns at compile time.

2
Comments Analyzed
TypeScript
Primary Language
API
Category

Source Discussions