= typescript =
* https://www.typescriptlang.org
* https://www.typescriptlang.org/docs/tutorial.html
== install ==
npm install -g typescript
== Compile ==
tsc helloworld.ts
== kate ==
https://github.com/PrettyFlower/KateTypeScriptSyntaxHighlighting
{{{
wget https://github.com/PrettyFlower/KateTypeScriptSyntaxHighlighting/raw/master/typescript.xml
cp typescript.xml /usr/share/apps/katepart/syntax/typescript.xml
}}}
With let keyword added
{{{#!highlight xml
- if
- else
- for
- in
- while
- do
- continue
- break
- with
- try
- catch
- finally
- switch
- case
- new
- var
- function
- return
- delete
- true
- false
- void
- throw
- typeof
- const
- default
- this
- null
- undefined
- class
- export
- declare
- module
- import
- static
- interface
- implements
- constructor
- public
- private
- string
- number
- bool
- any
- extends
- let
}}}
== Sample code typescript for browser ==
{{{
npm install -g typescript
npm install -g webpack
}}}
=== greeter.html ===
{{{
TypeScript Greeter
//lib.ts
export function getText(){
return "text";
}
=== greeter.ts ===
{{{
import {getText} from "./lib";
interface Person {
firstName: string;
lastName: string;
}
function greeterPerson(p:Person) {
return "Hello GP, " + p.firstName + ' ' + p.lastName + ' '
+ getText() ;
}
function greeter(person:string) {
return "Hello, " + person;
}
var user = "XPTO User";
//document.body.innerHTML = greeter(user);
document.body.innerHTML = greeterPerson(
{firstName:"First",lastName:"Last"}
);
}}}
=== tsconfig.json ===
{{{
{
"compilerOptions": {
"module": "es6",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true
},
"files": [ "greeter.ts", "lib.ts"]
}
}}}
=== webpack.config.js ===
{{{
var path = require('path');
module.exports = {
entry: ['./greeter.js','./lib.js'],
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
}
};
}}}
=== build ===
{{{
tsc
webpack --config webpack.config.js
}}}