Closed kylegoetz closed 6 years ago
And your heroes.component.ts is correct?? how do you have defined heroes? Like this
heroes: Hero[];
I'm having the same issue. I'm sure everything else is correct. I wouldn't have gotten to this step in the tutorial if it wasn't. The tutorial does not tell you to declare heroes: Hero[];
in heroes.component.ts.
It says to do this: heroes = HEROES;
./src/app/mock-heroes.js
Module parse failed: Unexpected token (3:19)
You may need an appropriate loader to handle this file type.
| import { Hero } from './hero';
|
| export const HEROES: Hero[] = [
| { id: 11, name: 'Mr. Nice' },
| { id: 12, name: 'Narco' },
Same issue for me, thought I was going nuts. (Might still be going nuts.)
UPDATE: mock-heroes and hero need to have the ".ts" extension, not ".js".
Coming back to this, is the problem that the file is called mock-heroes.js instead of .ts???
Yes, try it with .ts, and it works. I had the same issue.
Coming back to this, is the problem that the file is called mock-heroes.js instead of .ts???
My code is copied straight from the tutorial. It says to make the file
I did this and get the following error:
However, if I remove the
: Hero[]
from the file, it compiles and works correctly.I just installed angular-cli a few hours ago with
npm install -g @angular/cli
and then followed the tutorial.So I'm wondering if there's a TypeScript issue where whatever compiles my TS is a version that doesn't allow the implicit casting that appears to be going on in mock-heroes.js (array is id'd as Hero[] but elements are actual JS objects), so is the tutorial going off some TS feature that doesn't exist in whatever is installed by angular-cli?