backbone.js - creating typescript classes to work with existing Javascript and Backbone objects -


i started working on project backbone , javascript being used. i'm unsure how start integrating typescript. example, have namespace of our company precedes our views, models, objects, etc. creating backbone object without typescript:

company.views.mynewview = (function () { return backbone.view.extend({ } })(); 

so now, using typescript, thought like

class company.views.mynewview {  } 

however, typescript doesn't period in name. first question how use typescript existing namespace in project? namespaces defined as

var company = company || {}; company.views = company.views || {}; 

my second question more general. looking ahead, can typescript integrate existing project defined standard javascript? i'm not sure how access of non-typescript class objects. in advance.

edit: attempt integrate existing javascript objects

declare module company.views {     export class mynewrouter extends company.baserouter {       // not recognize company.baserouter     } } 

typescript has concept of modules. module equivalent company || {}.

so can following :

module company{     export module views{         export function mynewview(){             return <any>backbone.view.extend({ });         }     } } 

which compiles :

var company; (function (company) {     (function (views) {         function mynewview() {             return backbone.view.extend({             });         }         views.mynewview = mynewview;     })(company.views || (company.views = {}));     var views = company.views; })(company || (company = {})); 

a simpler example

the following typescript:

module company{     // need @ least 1 export      // compiler generate code     export var foo = 123; } 

generates:

var company; (function (company) {     company.foo = 123; })(company || (company = {})); 

for integrating existing js

you need create declarations typescript know js. js doesn't care if declare variable in 1 file , use in another. typescript since needs compile time checking.

the simplest declaration :

declare var somejsstuff:any;  

and can build there.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -