Skip to content

fix(types): Fix clone method type declaration to be an instance method rather than instance property#4925

Open
mistval wants to merge 1 commit intonodejs:mainfrom
mistval:patch-1
Open

fix(types): Fix clone method type declaration to be an instance method rather than instance property#4925
mistval wants to merge 1 commit intonodejs:mainfrom
mistval:patch-1

Conversation

@mistval
Copy link

@mistval mistval commented Mar 23, 2026

This relates to...

The Response type declaration currently declares clone as an instance property, but it's actually an instance method. This PR updates the type declaration to reflect that, and also makes the equivalent change to the Request type declaration which is in the same situation.

Rationale

The distinction between a function instance property and an instance method rarely matters, but can impact certain use cases, including trying to extend Response and override the method. For example this code emits TS errors yet works fine:

class ExtendResponse extends Response {
  public override clone(): Response {
    return super.clone();
  }
}

TS errors:

(Second line) Class 'Response' defines instance member property 'clone', but extended class 'ExtendResponse' defines it as instance member function.
(Third line) Class field 'clone' defined by the parent class is not accessible in the child class via super.

This change also aligns with the built in TS lib DOM which declares the method like so:

/**
 * The **`clone()`** method of the Response interface creates a clone of a response object, identical in every way, but stored in a different variable.
 *
 * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Response/clone)
 */
clone(): Response;

This rationale applies equally to Request.prototype.clone too.

Changes

  • Changes the type declaration of Response.clone() from readonly clone: () => Response to public clone (): Response.
  • Changes the type declaration of Request.clone() from readonly clone: () => Request to public clone (): Request.

Features

N/A

Bug Fixes

N/A

Breaking Changes and Deprecations

N/A

I can't think of a situation where this would break anything, as both before and after, typeof Response.prototype.clone is () => Response.

Status

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.

1 participant