{"record":{"id":"71326c368b757f25","repo":"angular/angular","slug":"decorator-arg-not-literal-71326c","errorCode":"DECORATOR_ARG_NOT_LITERAL","errorMessage":"@Service argument must be an object literal","messagePattern":"@Service argument must be an object literal","errorType":"error_code","errorClass":"FatalDiagnosticError","httpStatus":null,"severity":"error","filePath":"packages/compiler-cli/src/ngtsc/annotations/src/service.ts","lineNumber":237,"sourceCode":"    const typeArgumentCount = this.reflector.getGenericArityOfClass(clazz) || 0;\n    if (decorator.args === null) {\n      throw new FatalDiagnosticError(\n        ErrorCode.DECORATOR_NOT_CALLED,\n        decorator.node,\n        '@Service must be called',\n      );\n    }\n    if (decorator.args.length === 0) {\n      return {\n        name,\n        type,\n        typeArgumentCount,\n      };\n    } else if (decorator.args.length === 1) {\n      const metaNode = decorator.args[0];\n\n      if (!ts.isObjectLiteralExpression(metaNode)) {\n        throw new FatalDiagnosticError(\n          ErrorCode.DECORATOR_ARG_NOT_LITERAL,\n          metaNode,\n          '@Service argument must be an object literal',\n        );\n      }\n\n      // Resolve the fields of the literal into a map of field name to expression.\n      const meta = reflectObjectLiteral(metaNode);\n      let autoProvided: boolean | undefined;\n\n      if (meta.has('autoProvided')) {\n        const value = meta.get('autoProvided')!;\n\n        if (value.kind !== ts.SyntaxKind.TrueKeyword && value.kind !== ts.SyntaxKind.FalseKeyword) {\n          throw new FatalDiagnosticError(\n            ErrorCode.VALUE_HAS_WRONG_TYPE,\n            metaNode,\n            '`autoProvided` property must be a boolean literal',","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/angular/angular/blob/51cb07e98081ab7e4e84a9e0949266a8e19cca84/packages/compiler-cli/src/ngtsc/annotations/src/service.ts#L219-L255","documentation":"When @Service is called with one argument, that argument must be a literal object expression. The handler checks ts.isObjectLiteralExpression on decorator.args[0]; a variable reference, string, or any other expression throws DECORATOR_ARG_NOT_LITERAL. Like other Angular annotation handlers, the compiler statically reflects the literal's fields (autoProvided, factory) and cannot evaluate referenced configuration.","triggerScenarios":"@Service(SERVICE_OPTS) with a constant defined elsewhere; @Service('name') string form; @Service({...defaults}) spreads or assertion-wrapped values.","commonSituations":"Centralizing service configuration in constants; codemods extracting decorator options into variables; unfamiliarity with the literal-only requirement shared by all Angular decorators.","solutions":["Inline the options: @Service({autoProvided: true})","Keep the call empty (@Service()) if you have no options to pass","Ensure the argument is a plain object literal, not a reference, spread, or assertion"],"exampleFix":"// before\nconst opts = {autoProvided: true};\n@Service(opts)\nexport class Cache {}\n\n// after\n@Service({autoProvided: true})\nexport class Cache {}","handlingStrategy":"validation","validationCode":"import ts from 'typescript';\n\nfunction serviceArgIsObjectLiteral(dec: ts.Decorator): boolean {\n  if (!ts.isCallExpression(dec.expression)) return true;\n  const [arg] = dec.expression.arguments;\n  return arg === undefined || ts.isObjectLiteralExpression(arg);\n}","typeGuard":"function isServiceMetaLiteral(arg: ts.Expression | undefined): arg is ts.ObjectLiteralExpression | undefined {\n  return arg === undefined || ts.isObjectLiteralExpression(arg);\n}","tryCatchPattern":null,"preventionTips":["Inline @Service options as an object literal; never pass a variable","Re-use the same mental model as @Component/@NgModule: Angular decorators only accept inline literals","Avoid spreads and assertions inside decorator arguments"],"tags":["angular","ngtsc","decorator","service","compile-time","ast-literal"],"backgroundTag":"decorator-requires-object-literal","analyzedSha":"51cb07e98081ab7e4e84a9e0949266a8e19cca84","analyzedAt":"2026-08-22T07:04:54.531Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}