{"record":{"id":"3d5837eae26f579c","repo":"angular/angular-cli","slug":"can-only-specify-one-value-for-implements-when-gen","errorCode":null,"errorMessage":"Can only specify one value for implements when generating a functional guard.","messagePattern":"Can only specify one value for implements when generating a functional guard\\.","errorType":"exception","errorClass":"SchematicsException","httpStatus":null,"severity":"error","filePath":"packages/schematics/angular/guard/index.ts","lineNumber":20,"sourceCode":" * @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\n    if (options.implements.includes(GuardInterface.CanMatch)) {\n      routerNamedImports.push('Route', 'UrlSegment');\n","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/schematics/angular/guard/index.ts#L2-L38","documentation":"Functional guards (`--functional`) are a single function typed by exactly one interface, so the schematic forbids multiple `implements` values in that mode. When `options.implements.length > 1 && options.functional`, this SchematicsException is thrown. Class-based guards can implement several interfaces; functional ones cannot.","triggerScenarios":"Running `ng generate guard <name> --functional --implements CanActivate,CanDeactivate` (two or more comma-separated values with the functional flag), or passing an array of multiple interface names programmatically with `functional: true`.","commonSituations":"Users upgrading from class-based guard generation who kept multi-value `--implements` habits; copy-pasted commands from class-guard examples; custom tooling that appends multiple interfaces unconditionally.","solutions":["Provide only one value when using `--functional`: `ng g guard auth --functional --implements CanActivate`.","If you truly need multiple interfaces, drop `--functional` to generate a class-based guard implementing several.","Generate multiple separate functional guards, one per interface, and compose them in your route config."],"exampleFix":"// before\nng g guard auth --functional --implements CanActivate,CanDeactivate\n// after\nng g guard auth --functional --implements CanActivate\n// or class-based:\nng g guard auth --implements CanActivate,CanDeactivate","handlingStrategy":"validation","validationCode":"if (options.functional && Array.isArray(options.implements) && options.implements.length > 1) {\n  throw new Error('Functional guards accept exactly one --implements value.');\n}","typeGuard":"function validFunctionalOptions(o: { functional?: boolean; implements?: string[] }): boolean {\n  return !(o.functional && (o.implements?.length ?? 0) > 1);\n}","tryCatchPattern":"try {\n  await runSchematic('guard', options);\n} catch (e) {\n  if (e instanceof SchematicsException && e.message.includes('only specify one value')) {\n    console.error('Use one --implements value with --functional, or drop --functional for multi-interface class guards.');\n  } else throw e;\n}","preventionTips":["Pair `--functional` with exactly one interface name.","Generate separate functional guards per interface instead of one guard with many.","Update legacy scripts that pass comma-separated --implements lists together with --functional."],"tags":["angular","schematics","guard","invalid-option-combination"],"backgroundTag":"incompatible-options","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}