Here is SystemJS + TypeScript plunk, created from official Angular plunk template.
It throws
(SystemJS) SyntaxError: Missing initializer in const declaration
at eval ()
...
error and obviously evaluates .ts file as ordinary JavaScript when the file doesn't contain import
or export
statements:
main.ts
const foo: boolean = 'foo';
console.log(foo);
config.js
System.config({
//use typescript for compilation
transpiler: 'typescript',
//typescript compiler options
typescriptOptions: {
emitDecoratorMetadata: true
},
paths: {
'npm:': 'https://unpkg.com/'
},
//map tells the System loader where to look for things
map: {
'app': './src',
...
},
//packages defines our app package
packages: {
app: {
main: './main.ts',
defaultExtension: 'ts'
},
...
}
});
index.html
...
<script src="https://unpkg.com/[email protected]/dist/system.js"></script>
<script src="config.js"></script>
<script>
System.import('app')
.catch(console.error.bind(console));
</script>
...
But the same plunk is fine when the file has signs of ES6 module:
main.ts
const foo: boolean = 'foo';
console.log(foo);
export default null;
Obviously, if a file has .ts extension, I would prefer to evaluate it as TypeScript, whether it imports something or not.
Why does this happen in this setup? How can this be fixed?
plugin-typescript
.systemjs
does not come with transpiler so justtranspiler: 'typescript'
does not work – Daciadacieexport
statement. This is what the question says. Otherwiseconst foo: boolean = 'foo'
would throw a syntax error, wouldn't it? – Rustle