Skip to content

Implicit derived constructor does not forward its arguments to a native base's super(): class X extends AsyncResource {} throws on new X("type") #10623

Description

@proggeramlug

Found while fixing #10453 (PR #10621), confirmed present on both the baseline and the fix, so it is a
separate defect rather than a regression.

const { AsyncResource } = require("node:async_hooks");
class NoCtor extends AsyncResource {}
new NoCtor("MyResource");   // throws: "type" argument must be of type string

A derived class with no explicit constructor gets an implicit one that should forward its arguments to
super(...). Against a native base it does not — the native super() sees no arguments, so AsyncResource's
required type string is missing and it throws.

Node runs this fine. The explicit form works today:

class WithCtor extends AsyncResource {
  constructor(type) { super(type); }   // works
}

This is likely not AsyncResource-specific — any native base with required constructor arguments should show it.
Worth checking Error subclasses, EventEmitter, and the stream classes for the same shape.

Related: CLAUDE.md's "Native base-class subclassing" known-weak area notes that a native base's surface is
installed at super() time, and that keying behaviour on the literal extends name loses it for fieldless
classes — a fieldless, constructor-less subclass is exactly that shape.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    package-auditFound by the 2026 package audit: compiling real npm packages from source instead of native bindings

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions