From 2a453fef509e26548db678aac29a292cd3f2e16f Mon Sep 17 00:00:00 2001 From: Dave Allen Date: Wed, 28 Aug 2013 13:33:21 -0700 Subject: [PATCH 01/10] Changed some return types from type Object to type any so properties and methods of return types can be called --- meteor/meteor.d.ts | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/meteor/meteor.d.ts b/meteor/meteor.d.ts index 83c3c9428..3e270ce12 100644 --- a/meteor/meteor.d.ts +++ b/meteor/meteor.d.ts @@ -89,19 +89,9 @@ interface IMeteor { /************ * Accounts * ************/ - user(): { - _id: string; - username: string; - emails?: { - address: string; - verified: boolean; - } - profile?: Object; - services?: Object; - createdAt?: number; - }; + user(): IMeteorUser; userId(): string; - users: IMeteorCollection; + users: IMeteorUserCollection; loggingIn(): boolean; logout(callback?: Function): void; loginWithPassword(user: Object, password: string, callback?: Function): void; @@ -191,8 +181,8 @@ interface IMeteor { ***************/ interface IMeteorCollection { find(selector?, options?: Object): IMeteorCursor; - findOne(selector, options?: Object): Object; - insert(doc, callback?: Function): number; + findOne(selector, options?: Object): any; + insert(doc: Object, callback?: Function): string; update(selector, modifier, options?: Object, callback?: Function): void; remove(selector, callback?: Function): void; allow(options: Object): boolean; @@ -244,7 +234,7 @@ interface IMeteorManager { created(callback: Function): void; destroyed(callback: Function): void; events(eventMap: {[eventType: string]: Function}): void; - helpers(helpers: Object): Object; + helpers(helpers: Object): any; preserve(selector: Object): void; } @@ -288,6 +278,29 @@ interface IMeteorHandle { /************************** * Accounts and Passwords * **************************/ +interface IMeteorUser { + _id?: string; + username?: string; + emails?: { + address: string; + verified: boolean; + } + profile?: any; + services?: any; + createdAt?: number; +} + +interface IMeteorUserCollection { + find(selector?, options?: Object): IMeteorCursor; + findOne(selector, options?: Object): IMeteorUser; + insert(doc: IMeteorUser, callback?: Function): IMeteorUser; + update(selector, modifier, options?: Object, callback?: Function): void; + remove(selector, callback?: Function): void; + allow(options: Object): boolean; + deny(options: Object): boolean; + ObjectID(hexString?: string): Object; +} + interface IMeteorAccounts { config(options: { sendVerificationEmail?: boolean; From b53ca376666a4fa9d60e0989d0df6151aa401cc2 Mon Sep 17 00:00:00 2001 From: Dave Allen Date: Wed, 28 Aug 2013 15:48:19 -0700 Subject: [PATCH 02/10] Added usage notes --- meteor/README.md | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 meteor/README.md diff --git a/meteor/README.md b/meteor/README.md new file mode 100644 index 000000000..6b8647e9b --- /dev/null +++ b/meteor/README.md @@ -0,0 +1,69 @@ +#Meteor Type Definitions Usage Notes + +In order to effectively write your Meteor app with TypeScript, there are a few things you will need to do since simply referencing this Meteor type definition file and renaming all of you *.js files to *.ts will not work. + +##Referencing Meteor type definitions in your app +- Place the meteor.d.ts file in a directory (maybe `/lib/typescript`) +- Add `/// ` to the top of any file + +This will make these Typescript variables/objects available across your application: + +- Meteor +- Session +- Deps +- Accounts +- Match +- Computation +- Dependency +- EJSON +- HTTO +- Email +- Assets +- DPP + +*Please note that the Template variable is not automatically available. You need to follow the instructions below to use the Template variable.* + +##Defining Templates +In order to call `Template.yourTemplateName.method`, you will need to create a simple TypeScript definition file that declares a Template variable containing a list of template view-models/managers of type IMeteorViewModel (or IMeteorManager, which contains the same contents). A good place for this definition could be `/client/views/view-model-types.d.ts`. Here is an example of that file: + + /// + + declare var Template: { + newPosts: IMeteorViewModel; + bestPosts: IMeteorViewModel; + postsList: IMeteorViewModel; + comment: IMeteorViewModel; + commentSubmit: IMeteorViewModel; + notifications: IMeteorViewModel; + postPage: IMeteorViewModel; + postEdit: IMeteorViewModel; + postItem: IMeteorViewModel; + postNew: IMeteorViewModel; + header: IMeteorViewModel; + } + +After you create this file, you may access the Template variable by declaring something like `/// ` at the top of any file containing references to Template. Something like Template.postsList would then be accessible and get all the benefits of typing. + + +##Defining Collections +In TypeScript, creating global variables is not allowed, and in a Meteor app, creating local variables (using `var `) limits their scope to the file they are in. However, it is often necessary in a Meteor app to define variables that can be used across files, such as collections. In the case of collections, one way to work around this is to wrap each collections within a module, and then make the module globally accessible. Here is an example of posts.ts: + + module PostsModel { + export var Posts = new Meteor.Collection('posts'); + }; + + this.PostsModel = PostsModel; + +You can then access the Posts collection by placing `/// ` at the top of a typescript file and creating a call like this: + + PostsModel.Posts.findOne(Session.get('currentPostId')); + + +##Reference app +A simple Meteor application created with TypeScript is listed below. It is based on the Microscope reference application in the [Discover Meteor](http://www.discovermeteor.com/ "http://www.discovermeteor.com/") book. + +- Sample Site: +- Code (TypeScript and transpiled JS): + +##Meteor package +There will hopefully be a Meteor package soon listed on [Atmosphere](http://atmosphere.meteor.com "http://atmosphere.meteor.com") that can be easily added using "mrt add meteor". \ No newline at end of file From cf9f92a8c9fe77c5e8c84998f5fad0fa328d7148 Mon Sep 17 00:00:00 2001 From: Dave Allen Date: Wed, 28 Aug 2013 16:01:38 -0700 Subject: [PATCH 03/10] Fixed some typos --- meteor/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/meteor/README.md b/meteor/README.md index 6b8647e9b..2f429d13e 100644 --- a/meteor/README.md +++ b/meteor/README.md @@ -1,10 +1,10 @@ #Meteor Type Definitions Usage Notes -In order to effectively write your Meteor app with TypeScript, there are a few things you will need to do since simply referencing this Meteor type definition file and renaming all of you *.js files to *.ts will not work. +In order to effectively write your Meteor app with TypeScript, there are a few things you will need to do since simply referencing this Meteor type definition file and renaming all of your *.js files to *.ts will not work. ##Referencing Meteor type definitions in your app - Place the meteor.d.ts file in a directory (maybe `/lib/typescript`) -- Add `/// ` to the top of any file +- Add `/// ` to the top of any TypeScript file This will make these Typescript variables/objects available across your application: @@ -24,7 +24,7 @@ This will make these Typescript variables/objects available across your applicat *Please note that the Template variable is not automatically available. You need to follow the instructions below to use the Template variable.* ##Defining Templates -In order to call `Template.yourTemplateName.method`, you will need to create a simple TypeScript definition file that declares a Template variable containing a list of template view-models/managers of type IMeteorViewModel (or IMeteorManager, which contains the same contents). A good place for this definition could be `/client/views/view-model-types.d.ts`. Here is an example of that file: +In order to call `Template.yourTemplateName.method`, you will need to create a simple TypeScript definition file that declares a Template variable containing a list of template view-models/managers of type IMeteorViewModel (or IMeteorManager, which is the same as IMeteorViewModel). A good place for this definition could be `/client/views/view-model-types.d.ts`. Here is an example of that file: /// @@ -46,7 +46,7 @@ After you create this file, you may access the Template variable by declaring so ##Defining Collections -In TypeScript, creating global variables is not allowed, and in a Meteor app, creating local variables (using `var `) limits their scope to the file they are in. However, it is often necessary in a Meteor app to define variables that can be used across files, such as collections. In the case of collections, one way to work around this is to wrap each collections within a module, and then make the module globally accessible. Here is an example of posts.ts: +In TypeScript, creating global variables is not allowed, and in a Meteor app, creating local variables (using `var `) limits variables' scope to the file. However, it is often necessary in a Meteor app to define variables that can be used across files, such as collections. In the case of collections, one way to work around this is to wrap each collection within a module, and then make the module globally accessible. Here is an example using posts.ts: module PostsModel { export var Posts = new Meteor.Collection('posts'); @@ -54,13 +54,13 @@ In TypeScript, creating global variables is not allowed, and in a Meteor app, cr this.PostsModel = PostsModel; -You can then access the Posts collection by placing `/// ` at the top of a typescript file and creating a call like this: +You can then access the Posts collection by placing `/// ` at the top of a TypeScript file. The call would look like this: PostsModel.Posts.findOne(Session.get('currentPostId')); ##Reference app -A simple Meteor application created with TypeScript is listed below. It is based on the Microscope reference application in the [Discover Meteor](http://www.discovermeteor.com/ "http://www.discovermeteor.com/") book. +A simple Meteor application created with TypeScript is listed below. It is based on the Microscope reference app in the [Discover Meteor](http://www.discovermeteor.com/ "http://www.discovermeteor.com/"). - Sample Site: - Code (TypeScript and transpiled JS): From 8661326d65f5e2f4f0269bce67d17652d177ba60 Mon Sep 17 00:00:00 2001 From: Dave Allen Date: Wed, 28 Aug 2013 16:16:50 -0700 Subject: [PATCH 04/10] More wordsmithing --- meteor/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/meteor/README.md b/meteor/README.md index 2f429d13e..a040b5e6a 100644 --- a/meteor/README.md +++ b/meteor/README.md @@ -6,7 +6,7 @@ In order to effectively write your Meteor app with TypeScript, there are a few t - Place the meteor.d.ts file in a directory (maybe `/lib/typescript`) - Add `/// ` to the top of any TypeScript file -This will make these Typescript variables/objects available across your application: +This will make these typed Meteor variables/objects available across your application: - Meteor - Session @@ -42,11 +42,11 @@ In order to call `Template.yourTemplateName.method`, you will need to create a s header: IMeteorViewModel; } -After you create this file, you may access the Template variable by declaring something like `/// ` at the top of any file containing references to Template. Something like Template.postsList would then be accessible and get all the benefits of typing. +After you create this file, you may access the Template variable by declaring something like `/// ` at the top of any TypeScript file containing references to Template. Something like `Template.postsList.helpers()` would then transpile successfully (and have the benefits of typing). ##Defining Collections -In TypeScript, creating global variables is not allowed, and in a Meteor app, creating local variables (using `var `) limits variables' scope to the file. However, it is often necessary in a Meteor app to define variables that can be used across files, such as collections. In the case of collections, one way to work around this is to wrap each collection within a module, and then make the module globally accessible. Here is an example using posts.ts: +In TypeScript, creating global variables is not allowed, and in a Meteor app, creating local variables (using `var `) limits variables' scope to the file. However, you will probably want to define variables, such as collections, that can be used across files. In the case of collections, one way to work around these limitations is to wrap each collection within a module, and then make the module globally accessible. Here is an example using posts.ts: module PostsModel { export var Posts = new Meteor.Collection('posts'); @@ -54,13 +54,13 @@ In TypeScript, creating global variables is not allowed, and in a Meteor app, cr this.PostsModel = PostsModel; -You can then access the Posts collection by placing `/// ` at the top of a TypeScript file. The call would look like this: +You can then access the Posts collection by placing `/// ` at the top of a TypeScript file. The code would look like this: PostsModel.Posts.findOne(Session.get('currentPostId')); ##Reference app -A simple Meteor application created with TypeScript is listed below. It is based on the Microscope reference app in the [Discover Meteor](http://www.discovermeteor.com/ "http://www.discovermeteor.com/"). +A simple Meteor application created with TypeScript is listed below. It is based on the Microscope reference app in [Discover Meteor](http://www.discovermeteor.com/ "http://www.discovermeteor.com/"). - Sample Site: - Code (TypeScript and transpiled JS): From 29f32ee4c4239684ed4cc660cbd2a1f5a5b2142b Mon Sep 17 00:00:00 2001 From: Dave Allen Date: Wed, 28 Aug 2013 16:21:20 -0700 Subject: [PATCH 05/10] More wordsmithing --- meteor/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meteor/README.md b/meteor/README.md index a040b5e6a..16a58f423 100644 --- a/meteor/README.md +++ b/meteor/README.md @@ -46,7 +46,7 @@ After you create this file, you may access the Template variable by declaring so ##Defining Collections -In TypeScript, creating global variables is not allowed, and in a Meteor app, creating local variables (using `var `) limits variables' scope to the file. However, you will probably want to define variables, such as collections, that can be used across files. In the case of collections, one way to work around these limitations is to wrap each collection within a module, and then make the module globally accessible. Here is an example using posts.ts: +In TypeScript, global variables are not allowed, and in a Meteor app, creating a local variable (using `var `) limits a variable's scope to the file. However, you will probably want to define variables, such as collections, that can be used across files. In the case of collections, one way to work around these limitations is to wrap each collection within a module, and then make the module globally accessible. Here is an example using posts.ts: module PostsModel { export var Posts = new Meteor.Collection('posts'); @@ -60,7 +60,7 @@ You can then access the Posts collection by placing `/// Date: Wed, 28 Aug 2013 16:28:17 -0700 Subject: [PATCH 08/10] Hopfeully last wordsmithing --- meteor/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meteor/README.md b/meteor/README.md index 6d8a39004..7cb70c348 100644 --- a/meteor/README.md +++ b/meteor/README.md @@ -66,4 +66,4 @@ A simple Meteor reference application created with TypeScript is listed below. - Code (TypeScript and transpiled JS): ##Meteor package -There will hopefully be a Meteor package soon listed on [Atmosphere](http://atmosphere.meteor.com "http://atmosphere.meteor.com") that can be easily added using 'mrt add meteor'. \ No newline at end of file +There will hopefully be a Meteor package soon listed on [Atmosphere](http://atmosphere.meteor.com "http://atmosphere.meteor.com") that can be easily added using `mrt add meteor`. \ No newline at end of file From e96690c7af5ae2854b2dcf33818d32a7139d09b3 Mon Sep 17 00:00:00 2001 From: Dave Allen Date: Wed, 28 Aug 2013 16:28:49 -0700 Subject: [PATCH 09/10] Hopfeully last wordsmithing --- meteor/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meteor/README.md b/meteor/README.md index 7cb70c348..48ced7f84 100644 --- a/meteor/README.md +++ b/meteor/README.md @@ -66,4 +66,4 @@ A simple Meteor reference application created with TypeScript is listed below. - Code (TypeScript and transpiled JS): ##Meteor package -There will hopefully be a Meteor package soon listed on [Atmosphere](http://atmosphere.meteor.com "http://atmosphere.meteor.com") that can be easily added using `mrt add meteor`. \ No newline at end of file +There will hopefully be a Meteor package soon listed on [Atmosphere](http://atmosphere.meteor.com "http://atmosphere.meteor.com") that can be easily added using `mrt add typescript`. \ No newline at end of file From b75496dc6abfc6298f226a9ec7a655736013f083 Mon Sep 17 00:00:00 2001 From: Dave Allen Date: Wed, 28 Aug 2013 17:01:16 -0700 Subject: [PATCH 10/10] Hopfeully last wordsmithing --- meteor/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meteor/README.md b/meteor/README.md index 48ced7f84..9ea635d45 100644 --- a/meteor/README.md +++ b/meteor/README.md @@ -1,6 +1,6 @@ #Meteor Type Definitions Usage Notes -In order to effectively write your Meteor app with TypeScript, there are a few extra things you will need to do in addition to simply referencing the Meteor type definition file and renaming all of your *.js files to *.ts (which will not work). +In order to effectively write your Meteor app with TypeScript, there are a few extra things you will need to do in addition to simply referencing the Meteor type definition file and renaming all of your *.js files to *.ts (which alone will not work). ##Referencing Meteor type definitions in your app - Place the meteor.d.ts file in a directory (maybe `/lib/typescript`)