TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the...

33

Transcript of TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the...

Page 1: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but
Page 2: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but
Page 3: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

TypeScript Playground

http://www.typescriptlang.org/Playground/

Page 4: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

IE F12

Page 5: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

SkyDrive

Page 6: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

Napa Office 365

Page 7: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

Azure Web Sites

Page 8: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

Our Journey (Part 1)

Page 9: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

We enjoy programming in JS*

*But we had some concerns

Page 10: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

static “pessimistic” dynamic “optimistic”

Application Scale JavaScript?

forgiving!

Page 11: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

Pains

Need to come up with “compensating” patterns for classes and modules/namespaces

Need patterns for managing callbacks

“JavaScript code ‘rots’ over time” --Ben

“Writing JavaScript code in a large

project is like carving code in stone”

--Alex

Page 12: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

TypeScript to rescue

TypeScript is a super set of JavaScript

Compiler / Library works cross browser

TypeScript is open source

Page 13: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but
Page 14: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

Writing better JavaScript

Formalization of common JavaScript patterns

Type inference and structural typing

Works with existing JavaScript libraries

Page 15: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

TypeScript Type Definitions

https://github.com/borisyankov/DefinitelyTyped

Page 16: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

Our Journey (Part 2)

Page 17: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

Growing Pains

Managing scripts and their order

Page 18: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

“our dependency graph was such a mess that each

area had a dependency on just about every other

area.” – Nick (from another project)

Growing Pains: Dependencies…

Page 19: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

Growing Pains: Eager loading

Page 20: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

Solution: AMD

A module/file must declare what other modules it requires in order to function

define id ‘moduleA' function

// code goes here

Page 21: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

TypeScript: External Modules

TypeScript supports code generation for CommonJS and the AMD module systems

tsc --module amd app.ts

tsc --module commonjs HttpServer.ts

import require 'vs/base/lib/winjs'

import = require('vs/editor/zoneWidget');

Page 22: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

Before/After

AMD in JavaScript

define([‘…./winjs.base‘, ‘…./zoneWidget’],

function(WinJS, ZoneWidget) { … }

);

TypeScript (AMD or CommonJS)

import require 'vs/base/lib/winjs'

import = require('vs/editor/zoneWidget');

Page 23: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

AMD Applied

Support à la carte consumption

Express CSS dependencies as well

/// <amd-dependency path=“vs/css!./actionbar” />

Page 24: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

After the AMD Migration Impressions

fresh

“Happy - no more globals, no

more cyclic dependencies,

faster startup” -Dirk

Page 25: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

Lazy Loading Contributions

csharp.tsexport class CSMode extends

modesExtensions.AbstractMode {

constructor() {

super('vs.languages.csharp');

}

// lots of code ….

}

csharp.contribution.tsmodeRegistry.registerMode(

[‘text/x-csharp'],

new Platform.Descriptor(

'vs/languages/csharp',

‘CSMode')

);

Page 26: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

Our Journey (Part 3)

Page 27: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

Componentization

Reuse TypeScript code as ‘binary’ JS components with a declarations file

Example using TypeScript language services as a component

tsc –declarations –out typescriptservices.js typescript.ts

Page 28: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

API

Type the API surface

JSDoc the API

Page 29: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

100% TypeScript

Migration is also code clean-up, but real work

“As I did conversions, I began typing various object literals I was passing

around as interfaces. Soon enough, I realized how inconsistent I was, the same

data was flowing around in at least 3 different formats. This is because of the

easiness through which you can create literals in JavaScript …. Need some

placeholder for data?... Just create a new literal object.” --Alex

“In JavaScript, you are really at the mercy of your ability to spell. “

delete this.markers[range.statMarkerId]; //start

--Joao

Page 30: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

TS Retrospective

bleeding edge

do it again

Page 31: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

http://www.typescriptlang.org/

Page 33: TypeScript - Jfokus · tsc –declarations –out typescriptservices.js typescript.ts. API Type the API surface JSDoc the API. 100% TypeScript Migration is also code clean-up, but

Thanks!