I was making good progress with a native-script project until this happened:
JS: EXCEPTION: Uncaught (in promise): ReferenceError: __assign is not defined
This is bubbling up from this line of code:
return [...state, { ...action.payload, success: false }];
Here's my tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noEmitHelpers": true,
"noEmitOnError": true
},
"exclude": [
"node_modules",
"platforms",
"**/*.aot.ts"
]
}
Typescript doesn't seem to be including it's helper __assign
function in the compiled source - which is their way of implementing the object spread syntax. Would any of you fine people happen to know why?
I'm happy to report I found the solution to this. This GitHub repo explains things quite nicely, but here's a quick rundown:
The flag noEmitHelpers
in tsconfig.json tells Typescript to omit these 'helpers' (such as __assign
) in every file that needs them.
{
"compilerOptions": {
// changing this to false does the job, but duplicates helpers across every file
"noEmitHelpers": false
}
}
The latest Typescript offers a better way to manage this, using the flag importHelpers
(see compiler options):
{
"compilerOptions": {
"noEmitHelpers": true,
"importHelpers": true // better
}
}
This'll get object spread working, and avoid code duplication across files.
You might also need to npm install tslib --save
to stop IDE errors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With