| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
JavaScript has a big advantage: Reach. You can run JavaScript on the client and the server, on your phone, your PC and even on your smart watch. Unfortunately, JavaScript has disadvantages when it comes to larger project implemented by multiple developers. TypeScript was built to solve this problem by adding a language layer on top of JavaScript. With TypeScript, you can create and add types where you need them. Compiler and IDE use them for compile-time type checking, IntelliSense, refactoring support, etc. In this demo-heavy session, Rainer Stropek (Microsoft Azure MVP, Microsoft Regional Director) introduces you to the TypeScript language. Rainer will start with the basics and work his way up to real-world examples using Node.js on the server and AngularJS on the client. This session requires basic JavaScript knowledge but no existing TypeScript experience.
Walkthrough startup code
Add TypeScript compiler: npm install typescript --save-dev
Create src/server.ts and demo some basic TypeScript concepts
Create tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"target": "es2015",
"noImplicitAny": true,
"sourceMap": true,
"moduleResolution": "node"
},
"exclude": [
"node_modules",
"typings/browser.d.ts",
"typings/browser"
]
}
Add gulp-typescript: npm install gulp-typescript --save-dev
Add TypeScript compile to Gulpfile
...
// Create TypeScript project from tsconfig.json
var tsClientProject = ts.createProject("tsconfig.json", {
typescript: require("typescript")
});
...
// Compile Typescript files
gulp.task("app", [], () => {
gulp.src(config.TS_SOURCES)
.pipe(sourcemaps.init())
.pipe(ts(tsClientProject))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.APP_DIST));
...
});
...
Talk about the need for type definitions for existing JS libraries
Add typings: npm install typings --save-dev
Init typings: typings init
Install typings for mongodb: typings install mongodb --save-dev
Install other typings: typings install body-parser cors express express-serve-static-core jasmine mime node serve-static --save-dev --ambient
Add postinstall to package.json
{
...
"scripts": {
...
"postinstall": "typings install"
},
...
}
Add basic src/server.ts code (demo IntelliSense for Express)
/// <reference path="../typings/main.d.ts" />
import * as express from "express";
import * as cors from "cors";
import * as bodyParser from "body-parser";
var app = express();
// Create express server
app.use(cors());
var bodyParserOptions = { };
app.use(bodyParser.json(bodyParserOptions));
// Start express server
var port: number = process.env.port || 1337;
app.listen(port, () => {
console.log(`Server is listening on port ${port}`);
});
Add/implement src/middleware/reviver.ts
Add/implement src/spec/reviver.spec.ts
Run tests: npm run test
Add reviver in src/server.ts
...
import reviver from "./middleware/reviver";
...
var bodyParserOptions = { reviver: reviver };
...
Setup tasks in Visual Studio Code and show building and testing
{
// See http://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "npm",
"isShellCommand": true,
"showOutput": "silent",
"suppressTaskName": true,
"tasks": [
{
"taskName": "build",
"args": ["run", "build"],
"problemMatcher": "$tsc"
},
{
"taskName": "test",
"args": ["run", "test"],
"showOutput": "always"
}
]
}
Add/implement src/model.ts
Add/implement src/config.ts
Add/implement src/dataAccess/contracts.ts
Add/implement src/dataAccess/store-base.ts
Add/implement src/dataAccess/event-store.ts
Add/implement src/dataAccess/participant-store.ts
Add/implement src/spec/config.ts and src/spec/dataAccess.spec.ts
Run tests: npm run test
Add/implement src/middleware/add-data-context.ts and src/middleware/get-data-context.ts
Add/implement src/middleware/events-api.ts
Add/implement full code for src/server.ts
Run server: npm run start
Demo web api with Postman
Walkthroug startup code
Add/implement app/app.component.ts
Run app: npm run start
| Back | FazBrowse Home | New Git URL |