{"record":{"id":"817a9e702b9129ac","repo":"denoland/deno","slug":"err-missing-args-817a9e","errorCode":"ERR_MISSING_ARGS","errorMessage":"The \"type\" argument must be specified","messagePattern":"The \"type\" argument must be specified","errorType":"error_code","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/event_target.mjs","lineNumber":110,"sourceCode":"const kPropagationStopped = Symbol(\"propagationStopped\");\n\nfunction isEvent(value) {\n  return typeof value?.[kType] === \"string\";\n}\n\nclass Event extends WebEvent {\n  /**\n   * @param {string} type\n   * @param {{\n   *   bubbles?: boolean,\n   *   cancelable?: boolean,\n   *   composed?: boolean,\n   * }} [options]\n   */\n  constructor(type, options = null) {\n    super(type, options);\n    if (arguments.length === 0) {\n      throw new ERR_MISSING_ARGS(\"type\");\n    }\n    validateObject(options, \"options\", {\n      allowArray: true,\n      allowFunction: true,\n      nullable: true,\n    });\n    const { cancelable, bubbles, composed } = { ...options };\n    this[kCancelable] = !!cancelable;\n    this[kBubbles] = !!bubbles;\n    this[kComposed] = !!composed;\n    this[kType] = `${type}`;\n    this[kDefaultPrevented] = false;\n    this[kTimestamp] = performance.now();\n    this[kPropagationStopped] = false;\n    this[kTarget] = null;\n    this[kIsBeingDispatched] = false;\n  }\n","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/event_target.mjs#L92-L128","documentation":"The Node-compatible Event class (from node:events / the internal event_target polyfill) requires a type string argument; constructing one with zero arguments throws ERR_MISSING_ARGS. The check uses arguments.length, so new Event(undefined) (one argument) is not this error - only a genuinely empty call or an empty spread is. This adds Node's stricter validation on top of the web Event base class.","triggerScenarios":"new Event() with no arguments; new Event(...types) where types is an empty array; Reflect.construct(Event, []) ; factory functions that spread possibly-empty argument lists.","commonSituations":"Event factories driven by dynamic data where the type field can be missing; porting browser code that always passed a type; destructuring or mapping code that produces an empty args array.","solutions":["Always pass a type explicitly: new Event('change')","Default it in factories: new Event(type ?? 'unnamed')","Validate arrays before spreading: types.length > 0 ? new Event(...types) : new Event('default')","Check data at the source - a missing event type usually means an upstream lookup failed"],"exampleFix":"// before\nconst ev = new Event(...types); // types === [] -> ERR_MISSING_ARGS\n\n// after\nconst ev = new Event(types[0] ?? 'change');","handlingStrategy":"validation","validationCode":"function makeEvent(types) {\n  if (!Array.isArray(types) || types.length === 0) {\n    throw new TypeError('makeEvent requires at least one event type');\n  }\n  return new Event(types[0]);\n}","typeGuard":null,"tryCatchPattern":"try {\n  ev = new Event(...args);\n} catch (e) {\n  if (e?.code === 'ERR_MISSING_ARGS') ev = new Event('unnamed');\n  else throw e;\n}","preventionTips":["Never spread possibly-empty arrays into constructors","Default event types in factories: new Event(type ?? 'change')","Treat a missing event type as an upstream data bug and validate at the source"],"tags":["events","event-target","argument-validation","node-compat"],"backgroundTag":"missing-required-argument","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}