Introduction
It’s not a secret that es5 now looks a little bit silly.
As a frontend engineer with love to TypeScript, i have a suggestion how to use TypeScript/ECMAScript2015 in Fuse.
First of all, the same technique can be applied to use es6 and babel, but for now i will describe steps to use TypeScript.
Step 1:
Install typescript and typings. To do this you need to do:
npm install typescript -g
npm install typings -g
Step 2:
Create a tsconfig.json file inside your project folder.
Here is example of tsconfig:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"noLib": false
}
}
Step 3:
Now just create a TS file and run
tsc --watch
Step 4:
Inside your .ux file just reference compiled js file like so
<JavaScript File="{TSFileName}.js"/>
Example
MainView.ts:
const Observable = require("FuseJS/Observable");
class ViewModel{
public name = Observable("TestVal");
public test = Observable("");
}
export const vm = new ViewModel();
MainView.ux:
<App>
<ClientPanel>
<JavaScript File="MainView.js"/>
<StackPanel>
<Text Value="{vm.name}"/>
<TextBox Value="{vm.name}"/>
</StackPanel>
</ClientPanel>
</App>
FAQ:
TypeScript compiler error ‘require’ is undefined
**Answer: ** Just open terminal and install node typings:
npm install @types/node --save-dev