Skip to content

DeployAccountMethod.with() breaks method chaining by not returning DeployAccountMethod #22315

@shiqicao

Description

@shiqicao

Problem

DeployAccountMethod.with(...) is supposed to allow fluent method chaining (e.g., setting a custom description), but it returns the base DeployMethod type instead of DeployAccountMethod. This breaks OOP expectations: any subclass that overrides with() has its type erased, forcing callers to either downcast or duplicate logic.

Expected behavior

DeployAccountMethod.with(...) should return DeployAccountMethod (or use a generic/self-referential return type pattern like this) so callers can continue chaining DeployAccountMethod-specific methods without losing type information.

Why this matters

This is a basic OOP contract violation. When a subclass's method returns the parent type, it destroys polymorphism and forces consumers to work around it (e.g., by reimplementing the subclass entirely just to fix the return type). Fluent APIs depend on each builder method returning the correct this type.

A common fix in TypeScript is to use a generic self-referential pattern or ensure overridden methods narrow the return type appropriately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions