0

I am trying to create a custom schematics.

I have created a template file which is to be generated by schematics.

This should create file with classname specified by inputs at command.

 export class <%= classify(name) %> {

}

But when I run using "npm run build", it throws error

    export class <%= classify(name) %> { 
               error TS1109: Expression expected.

I understand this is typescript error, But I am using "typescript": "~3.1.6" which should compile this.

I might be missing something basic. This is my first attempt with @angular/schematics.

halfer
  • 19,824
  • 17
  • 99
  • 186
Dheeraj Kumar
  • 3,917
  • 8
  • 43
  • 80
  • When I see this it's almost always because there's a syntax error and/or the function doesn't return a value when it should (often because of said syntax error). I suspect your logic is broken somewhere that we can't see here. – Tim Consolazio Dec 10 '18 at 13:32
  • Code which I have shown is the only content in ts file, also even without running I get underlined in red over the syntax after "export class" – Dheeraj Kumar Dec 10 '18 at 13:39
  • Maybe it's not possible to dynamically create a classname this way? I haven't used that kind of template markup in a long time, did you get this from an example we could see? I also assume you have the latest schematics SDK installed? (The latest TS probably matches up with the latest SDK). – Tim Consolazio Dec 10 '18 at 14:08
  • The code your displaying looks like a static asset (with templating options) included in your schematic, e.g., `files/class.ts`. I believe in order to execute the templating pattern, you need to pass a configuration object that includes the specified value, in this case **name**. Can you share the schematic code sample that calls your static asset with templating? I think I can help you out once I see a more complete sample. – ericksoen Jan 04 '19 at 19:29

0 Answers0