patterns TypeScript size
interface IModelChangeAccessor { insertText(position:IPosition, text:string): IEditorPosition; deleteText(range:IRange): IDeleteTextResult; } interface IEditableTextModel { change(callback: (changeAccessor:IModelChangeAccessor)=>any): … } Interfaces to be implemented
export interface IValidationFilter { (resource:IEventEmitter): boolean; } public constructor(filter:IValidationFilter) { } new Validator((resource)=>this.includeModel(resource)); Callbacks
interface ICommonEditorOptions { selectOnLineNumbers?:boolean; glyphMargin?:boolean; roundedSelection?:boolean; theme?:string; readOnly?:boolean; //… } Option bags
var options:IBuildData = JSON.parse(req.responseText); export interface IBuildData { requestId:string; logOutput?:string; buildOutput?:BuildOutput; killOutput?:KillOutput; } JSON structures
declare module WinJS { module Binding { //... } class Promise { //... } External types from other libraries
promise.then((result) => {...}, (err) => {...});
class Promise { then (success?: (value: T) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise ; //… } export interface ITypeDeclarationSupport { findTypeDeclaration(position:Editor.IPosition):Promise ; }
TSD: a package manager to search and install TypeScript definition files directly from the DefinitelyTyped repository.TypeScript DefinitelyTyped TSD: a package manager to search and install TypeScript definition files directly from the DefinitelyTyped repository.TypeScript DefinitelyTyped
We started with internal modules
patterns TypeScript size
“… our dependency graph was such a mess that each area had a dependency on just about every other area.”
File main.ts: import adder= require("./adder"); adder.add(3,4); File adder.ts: export function add(op1: number, op2: number):number { return op1+op2; }
var adder = require(“adder”); adder.add() tsc --module amd main.ts tsc --module commonjs main.ts
AMD in JavaScript define([‘…./winjs.base‘, ‘…./zoneWidget’], function(WinJS, ZoneWidget) { … } ); AMD in TypeScript import WinJS= require('vs/base/lib/winjs'); import ZoneWidget = require('vs/editor/zoneWidget');
csharp.ts export class CSMode extends AbstractMode { constructor() { super('vs.languages.csharp'); } // lots of code …. } csharp.contribution.ts modeRegistry.registerMode( [‘text/x-csharp'], new Platform.Descriptor( 'vs/languages/csharp/csharp', ‘CSMode') ); Registered on start-up Loaded on demand
patterns TypeScript size
“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.”
tsc –declarations –out typescriptservices.js typescript.ts
for MSDN Ultimate subscribers Go to SPECIAL OFFERS Partner Program