{"record":{"id":"6ac25ab6f7751437","repo":"angular/angular-cli","slug":"option-implements-is-required","errorCode":null,"errorMessage":"Option \"implements\" is required.","messagePattern":"Option \"implements\" is required\\.","errorType":"exception","errorClass":"SchematicsException","httpStatus":null,"severity":"error","filePath":"packages/schematics/angular/guard/index.ts","lineNumber":17,"sourceCode":"/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport { Rule, SchematicsException } from '@angular-devkit/schematics';\n\nimport { generateFromFiles } from '../utility/generate-from-files';\n\nimport { Implement as GuardInterface, Schema as GuardOptions } from './schema';\n\nexport default function (options: GuardOptions): Rule {\n  if (!options.implements) {\n    throw new SchematicsException('Option \"implements\" is required.');\n  }\n  if (options.implements.length > 1 && options.functional) {\n    throw new SchematicsException(\n      'Can only specify one value for implements when generating a functional guard.',\n    );\n  }\n\n  if (options.functional) {\n    const guardType = options.implements[0] + 'Fn';\n\n    return generateFromFiles({ ...options, templateFilesDirectory: './type-files' }, { guardType });\n  } else {\n    const implementations = options.implements\n      .map((implement) => (implement === 'CanDeactivate' ? 'CanDeactivate<unknown>' : implement))\n      .join(', ');\n    const commonRouterNameImports = ['ActivatedRouteSnapshot', 'RouterStateSnapshot'];\n    const routerNamedImports: string[] = [...options.implements, 'MaybeAsync', 'GuardResult'];\n","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/schematics/angular/guard/index.ts#L1-L35","documentation":"The `guard` schematic requires the `implements` option to know which guard interface(s) to generate (CanActivate, CanMatch, etc.). If `options.implements` is missing or empty, the generator cannot determine the guard's type or template, so it throws this SchematicsException immediately. The Angular CLI normally supplies this via the `--implements` flag (with a schema default), so this mainly fires on direct/programmatic schematic invocation.","triggerScenarios":"Invoking the guard schematic programmatically (e.g. via the Schematics API or a custom tool) without `implements` in the options object, or with `implements: []`, bypassing the CLI's schema validation.","commonSituations":"Custom internal tooling wrapping `@schematics/angular` guard generation; schematic collections extending the guard schematic and forgetting to pass `implements` through; older scripts written before schema defaults changed.","solutions":["Pass the flag on the CLI: `ng generate guard <name> --implements CanActivate` (or `CanMatch`, `CanActivateChild`, `CanDeactivate`, `CanLoad`, `CanActivateFn`-style functional names depending on version).","When calling the schematic programmatically, include `implements` in the options object passed to `execute`/`schedule`.","For functional guards, provide exactly one interface value, e.g. `--implements CanActivate --functional`."],"exampleFix":"// before\nschematicRunner.runSchematic('guard', { name: 'auth' });\n// after\nschematicRunner.runSchematic('guard', { name: 'auth', implements: ['CanActivate'] });","handlingStrategy":"validation","validationCode":"const opts = { name: 'auth', implements: ['CanActivate'] };\nif (!Array.isArray(opts.implements) || opts.implements.length === 0) {\n  throw new Error('Option \"implements\" is required, e.g. --implements CanActivate');\n}","typeGuard":"function hasImplements(o: { implements?: string[] }): o is { implements: string[] } {\n  return Array.isArray(o.implements) && o.implements.length > 0;\n}","tryCatchPattern":"try {\n  await runSchematic('guard', options);\n} catch (e) {\n  if (e instanceof SchematicsException && e.message.includes('Option \"implements\" is required')) {\n    console.error('Pass --implements <Interface> when generating a guard.');\n  } else throw e;\n}","preventionTips":["Always pass `--implements` when generating guards outside the interactive CLI prompt.","When wrapping the schematic in tooling, forward all user options including `implements`.","Check the guard schema (schema.json) for allowed interface values per CLI version."],"tags":["angular","schematics","guard","missing-option"],"backgroundTag":"missing-required-option","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}