{"record":{"id":"9b7376ecf9ad9714","repo":"angular/angular-cli","slug":"expected-an-object-options-as-second-argument","errorCode":null,"errorMessage":"Expected an object options as second argument.","messagePattern":"Expected an object options as second argument\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/angular_devkit/architect/src/jobs/simple-registry.ts","lineNumber":83,"sourceCode":"  ): void;\n\n  register<ArgumentT extends JsonValue, InputT extends JsonValue, OutputT extends JsonValue>(\n    nameOrHandler: JobName | JobHandler<ArgumentT, InputT, OutputT>,\n    handlerOrOptions: JobHandler<ArgumentT, InputT, OutputT> | RegisterJobOptions = {},\n    options: RegisterJobOptions = {},\n  ): void {\n    // Switch on the arguments.\n    if (typeof nameOrHandler == 'string') {\n      if (!isJobHandler(handlerOrOptions)) {\n        // This is an error.\n        throw new TypeError('Expected a JobHandler as second argument.');\n      }\n\n      this._register(nameOrHandler, handlerOrOptions, options);\n    } else if (isJobHandler(nameOrHandler)) {\n      if (typeof handlerOrOptions !== 'object') {\n        // This is an error.\n        throw new TypeError('Expected an object options as second argument.');\n      }\n\n      const name = options.name || nameOrHandler.jobDescription.name || handlerOrOptions.name;\n      if (name === undefined) {\n        throw new TypeError('Expected name to be a string.');\n      }\n\n      this._register(name, nameOrHandler, options);\n    } else {\n      throw new TypeError('Unrecognized arguments.');\n    }\n  }\n\n  protected _register<\n    ArgumentT extends JsonValue,\n    InputT extends JsonValue,\n    OutputT extends JsonValue,\n  >(","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular_devkit/architect/src/jobs/simple-registry.ts#L65-L101","documentation":"When the first argument to SimpleJobRegistry.register() is a JobHandler, the second argument (if supplied) must be the options object. This TypeError is thrown when a handler is passed first but the second argument is not a plain object — typically the name string was passed in the wrong position.","triggerScenarios":"register(handler, 'some-name') — passing a string name as the second argument instead of an options object like { name: 'some-name' }; also triggered by passing a function, number, or other non-object as the second argument alongside a handler.","commonSituations":"Developers expecting a register(name, handler) overload but passing (handler, name); older code written against a different registry API; confusion after switching between register(handler) and register(name, handler) forms.","solutions":["Pass the name inside the options object: registry.register(handler, { name: 'some-name' }).","Ensure the name is set on the handler itself via createJobHandler(..., { name: 'some-name' }) and call register(handler) with no second argument.","If you intended the name-first form, reorder arguments: registry.register('some-name', handler, options)."],"exampleFix":"// before\nregistry.register(myHandler, 'my-job');\n// after\nregistry.register(myHandler, { name: 'my-job' });","handlingStrategy":"validation","validationCode":"if (typeof secondArg !== 'undefined' && (secondArg === null || typeof secondArg !== 'object' || Array.isArray(secondArg))) {\n  throw new Error('second argument to register(handler, ...) must be an options object');\n}","typeGuard":"function isRegisterOptions(v) {\n  return v === undefined || (v !== null && typeof v === 'object' && !Array.isArray(v));\n}","tryCatchPattern":"try {\n  registry.register(handler, opts);\n} catch (e) {\n  if (e instanceof TypeError && /object options as second argument/.test(e.message)) {\n    throw new Error(`bad second argument type: ${typeof opts} — pass { name: '...' } instead`);\n  }\n  throw e;\n}","preventionTips":["Pass names via { name: '...' } options, never as a bare string second argument","Prefer register(handler) with the name baked into jobDescription","Lint for calls passing a string literal as the second argument of register","Document the two valid overloads in team code style guides"],"tags":["typescript","typeerror","architect","job-registry","wrong-arguments"],"backgroundTag":"invalid-argument-type","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}