From 54d6e6fb6ba332294e8183b6d63d5585ed139537 Mon Sep 17 00:00:00 2001 From: Dave Allen Date: Wed, 10 Jun 2015 12:19:26 -0700 Subject: [PATCH 1/3] Added _.includes method. This closes #4610. --- lodash/lodash-tests.ts | 5 ++++ lodash/lodash.d.ts | 53 +++++++++++++++++++++++++++++++++++------- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 633c4ed0d..1484ac048 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -371,6 +371,11 @@ result = _.include([1, 2, 3], 1, 2); result = _.include({ 'name': 'moe', 'age': 40 }, 'moe'); result = _.include('curly', 'ur'); +result = _.includes([1, 2, 3], 1); +result = _.includes([1, 2, 3], 1, 2); +result = _.includes({ 'name': 'moe', 'age': 40 }, 'moe'); +result = _.includes('curly', 'ur'); + result = <_.Dictionary>_.countBy([4.3, 6.1, 6.4], function (num) { return Math.floor(num); }); result = <_.Dictionary>_.countBy([4.3, 6.1, 6.4], function (num) { return this.floor(num); }, Math); result = <_.Dictionary>_.countBy(['one', 'two', 'three'], 'length'); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 9cb55485d..86e72e468 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -2172,7 +2172,7 @@ declare module _ { ...indexes: number[]): T[]; } - //_.contains + //_.includes interface LoDashStatic { /** * Checks if a given value is present in a collection using strict equality for comparisons, @@ -2182,13 +2182,49 @@ declare module _ { * @param fromIndex The index to search from. * @return True if the target element is found, else false. **/ + includes( + collection: Array, + target: T, + fromIndex?: number): boolean; + + /** + * @see _.includes + **/ + includes( + collection: List, + target: T, + fromIndex?: number): boolean; + + /** + * @see _.includes + * @param dictionary The dictionary to iterate over. + * @param key The key in the dictionary to search for. + **/ + includes( + dictionary: Dictionary, + key: string, + fromIndex?: number): boolean; + + /** + * @see _.includes + * @param searchString the string to search + * @param targetString the string to search for + **/ + includes( + searchString: string, + targetString: string, + fromIndex?: number): boolean; + + /** + * @see _.includes + **/ contains( collection: Array, target: T, fromIndex?: number): boolean; /** - * @see _.contains + * @see _.includes **/ contains( collection: List, @@ -2196,7 +2232,7 @@ declare module _ { fromIndex?: number): boolean; /** - * @see _.contains + * @see _.includes * @param dictionary The dictionary to iterate over. * @param key The key in the dictionary to search for. **/ @@ -2206,7 +2242,7 @@ declare module _ { fromIndex?: number): boolean; /** - * @see _.contains + * @see _.includes * @param searchString the string to search * @param targetString the string to search for **/ @@ -2215,8 +2251,9 @@ declare module _ { targetString: string, fromIndex?: number): boolean; + /** - * @see _.contains + * @see _.includes **/ include( collection: Array, @@ -2224,7 +2261,7 @@ declare module _ { fromIndex?: number): boolean; /** - * @see _.contains + * @see _.includes **/ include( collection: List, @@ -2232,7 +2269,7 @@ declare module _ { fromIndex?: number): boolean; /** - * @see _.contains + * @see _.includes **/ include( dictionary: Dictionary, @@ -2240,7 +2277,7 @@ declare module _ { fromIndex?: number): boolean; /** - * @see _.contains + * @see _.includes **/ include( searchString: string, From 4ae40d711d22819c4ded9f88532608c109bd35d1 Mon Sep 17 00:00:00 2001 From: Dave Allen Date: Tue, 6 Oct 2015 12:10:09 -0700 Subject: [PATCH 2/3] Overwrote lodash.d.ts with latest from DefinitelyTyped repo --- lodash/lodash.d.ts | 53 +++++++--------------------------------------- 1 file changed, 8 insertions(+), 45 deletions(-) diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 5f5c669b0..e18e5f6b3 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -2422,7 +2422,7 @@ declare module _ { ): LoDashArrayWrapper; } - //_.includes + //_.contains interface LoDashStatic { /** * Checks if a given value is present in a collection using strict equality for comparisons, @@ -2432,49 +2432,13 @@ declare module _ { * @param fromIndex The index to search from. * @return True if the target element is found, else false. **/ - includes( - collection: Array, - target: T, - fromIndex?: number): boolean; - - /** - * @see _.includes - **/ - includes( - collection: List, - target: T, - fromIndex?: number): boolean; - - /** - * @see _.includes - * @param dictionary The dictionary to iterate over. - * @param key The key in the dictionary to search for. - **/ - includes( - dictionary: Dictionary, - key: string, - fromIndex?: number): boolean; - - /** - * @see _.includes - * @param searchString the string to search - * @param targetString the string to search for - **/ - includes( - searchString: string, - targetString: string, - fromIndex?: number): boolean; - - /** - * @see _.includes - **/ contains( collection: Array, target: T, fromIndex?: number): boolean; /** - * @see _.includes + * @see _.contains **/ contains( collection: List, @@ -2482,7 +2446,7 @@ declare module _ { fromIndex?: number): boolean; /** - * @see _.includes + * @see _.contains * @param dictionary The dictionary to iterate over. * @param value The value in the dictionary to search for. **/ @@ -2492,7 +2456,7 @@ declare module _ { fromIndex?: number): boolean; /** - * @see _.includes + * @see _.contains * @param searchString the string to search * @param targetString the string to search for **/ @@ -2501,9 +2465,8 @@ declare module _ { targetString: string, fromIndex?: number): boolean; - /** - * @see _.includes + * @see _.contains **/ include( collection: Array, @@ -2511,7 +2474,7 @@ declare module _ { fromIndex?: number): boolean; /** - * @see _.includes + * @see _.contains **/ include( collection: List, @@ -2519,7 +2482,7 @@ declare module _ { fromIndex?: number): boolean; /** - * @see _.includes + * @see _.contains **/ include( dictionary: Dictionary, @@ -2527,7 +2490,7 @@ declare module _ { fromIndex?: number): boolean; /** - * @see _.includes + * @see _.contains **/ include( searchString: string, From 22d5a3bccc039004944982be9967f52a12d9d8c7 Mon Sep 17 00:00:00 2001 From: Dave Allen Date: Wed, 7 Oct 2015 14:25:59 -0700 Subject: [PATCH 3/3] Updated definitions for Meteor version 1.2.0.2 --- meteor/meteor-tests.ts | 288 ++++++++++++++++++++++++++++++----------- meteor/meteor.d.ts | 82 +++++------- 2 files changed, 245 insertions(+), 125 deletions(-) diff --git a/meteor/meteor-tests.ts b/meteor/meteor-tests.ts index 6c5c24083..e6f1e6f28 100644 --- a/meteor/meteor-tests.ts +++ b/meteor/meteor-tests.ts @@ -1,16 +1,25 @@ /// + /** * All code below was copied from the examples at http://docs.meteor.com/. * When necessary, code was added to make the examples work (e.g. declaring a variable * that was assumed to have been declared earlier) */ + + /*********************************** Begin setup for tests ******************************/ var Rooms = new Mongo.Collection('rooms'); var Messages = new Mongo.Collection('messages'); -var Monkeys = new Mongo.Collection('monkeys'); +interface MonkeyDAO { + _id: string; + name: string; +} +var Monkeys = new Mongo.Collection('monkeys'); //var x = new Mongo.Collection('x'); //var y = new Mongo.Collection('y'); /********************************** End setup for tests *********************************/ + + /** * From Core, Meteor.startup section * Tests Meteor.isServer, Meteor.startup, Collection.insert(), Collection.find() @@ -18,26 +27,30 @@ var Monkeys = new Mongo.Collection('monkeys'); if (Meteor.isServer) { Meteor.startup(function () { if (Rooms.find().count() === 0) { - Rooms.insert({ name: "Initial room" }); + Rooms.insert({name: "Initial room"}); } }); } + /** * From Publish and Subscribe, Meteor.publish section **/ Meteor.publish("rooms", function () { - return Rooms.find({}, { fields: { secretInfo: 0 } }); + return Rooms.find({}, {fields: {secretInfo: 0}}); }); + Meteor.publish("adminSecretInfo", function () { - return Rooms.find({ admin: this.userId }, { fields: { secretInfo: 1 } }); + return Rooms.find({admin: this.userId}, {fields: {secretInfo: 1}}); }); + Meteor.publish("roomAndMessages", function (roomId) { check(roomId, String); return [ - Rooms.find({ _id: roomId }, { fields: { secretInfo: 0 } }), - Messages.find({ roomId: roomId }) + Rooms.find({_id: roomId}, {fields: {secretInfo: 0}}), + Messages.find({roomId: roomId}) ]; }); + /** * Also from Publish and Subscribe, Meteor.publish section */ @@ -46,45 +59,55 @@ Meteor.publish("counts-by-room", function (roomId) { check(roomId, String); var count = 0; var initializing = true; - var handle = Messages.find({ roomId: roomId }).observeChanges({ + var handle = Messages.find({roomId: roomId}).observeChanges({ added: function (id) { count++; - // if (!initializing) - // Todo: Not sure how to define in typescript - // self.changed("counts", roomId, {count: count}); +// if (!initializing) + +// Todo: Not sure how to define in typescript +// self.changed("counts", roomId, {count: count}); }, removed: function (id) { count--; - // Todo: Not sure how to define in typescript - // self.changed("counts", roomId, {count: count}); +// Todo: Not sure how to define in typescript +// self.changed("counts", roomId, {count: count}); } }); + initializing = false; - // Todo: Not sure how to define in typescript - // self.added("counts", roomId, {count: count}); + +// Todo: Not sure how to define in typescript +// self.added("counts", roomId, {count: count}); self.ready(); + self.onStop(function () { handle.stop(); }); }); + var Counts = new Mongo.Collection("counts"); + Tracker.autorun(function () { Meteor.subscribe("counts-by-room", Session.get("roomId")); }); + console.log("Current room has " + Counts.find(Session.get("roomId")).count + " messages."); + /** * From Publish and Subscribe, Meteor.subscribe section */ Meteor.subscribe("allplayers"); + /** * Also from Meteor.subscribe section */ Tracker.autorun(function () { - Meteor.subscribe("chat", { room: Session.get("current-room") }); + Meteor.subscribe("chat", {room: Session.get("current-room")}); Meteor.subscribe("privateMessages"); }); + /** * From Methods, Meteor.methods section */ @@ -92,20 +115,25 @@ Meteor.methods({ foo: function (arg1, arg2) { check(arg1, String); check(arg2, [Number]); + var you_want_to_throw_an_error = true; if (you_want_to_throw_an_error) throw new Meteor.Error("404", "Can't find my pants"); return "some return value"; }, + bar: function () { // .. do other stuff .. return "baz"; } }); + /** * From Methods, Meteor.Error section */ -throw new Meteor.Error("logged-out", "The user must be logged in to post a comment."); +throw new Meteor.Error("logged-out", + "The user must be logged in to post a comment."); + Meteor.call("methodName", function (error) { if (error.error === "logged-out") { Session.set("errorMessage", "Please log in to post a comment."); @@ -115,20 +143,39 @@ var error = new Meteor.Error("logged-out", "The user must be logged in to post a console.log(error.error === "logged-out"); console.log(error.reason === "The user must be logged in to post a comment."); console.log(error.details !== ""); + /** * From Methods, Meteor.call section */ -Meteor.call('foo', 1, 2, function (error, result) { }); +Meteor.call('foo', 1, 2, function (error, result) {} ); var result = Meteor.call('foo', 1, 2); -var Chatrooms = new Mongo.Collection("chatrooms"); -Messages = new Mongo.Collection("messages"); -var myMessages = Messages.find({ userId: Session.get('myUserId') }).fetch(); -Messages.insert({ text: "Hello, world!" }); -Messages.update(myMessages[0]._id, { $set: { important: true } }); + +/** + * From Collections, Mongo.Collection section + */ +// DA: I added the "var" keyword in there + +interface ChatroomsDAO { + _id?: string; +} +interface MessagesDAO { + _id?: string; +} +var Chatrooms = new Mongo.Collection("chatrooms"); +Messages = new Mongo.Collection("messages"); + +var myMessages = Messages.find({userId: Session.get('myUserId')}).fetch(); + +Messages.insert({text: "Hello, world!"}); + +Messages.update(myMessages[0]._id, {$set: {important: true}}); + var Posts = new Mongo.Collection("posts"); -Posts.insert({ title: "Hello world", body: "First post" }); +Posts.insert({title: "Hello world", body: "First post"}); + // Couldn't find assert() in the meteor docs //assert(Posts.find().count() === 1); + /** * Todo: couldn't figure out how to make this next line work with Typescript * since there is already a Collection constructor with a different signature @@ -138,48 +185,68 @@ Posts.insert({ title: "Hello world", body: "First post" }); Scratchpad.insert({number: i * 2}); assert(Scratchpad.find({number: {$lt: 9}}).count() === 5); **/ + var Animal = function (doc) { - // _.extend(this, doc); +// _.extend(this, doc); }; + // DA: I altered this to remove dependencies on Underscore Animal.prototype = { makeNoise: function () { console.log(this.sound); } }; + + +interface AnimalDAO { + _id?: string; + name: string; + sound: string; + makeNoise?: () => void; +} + // Define a Collection that uses Animal as its document -var Animals = new Mongo.Collection("Animals", { +var Animals = new Mongo.Collection("Animals", { transform: function (doc) { return new Animal(doc); } }); + // Create an Animal and call its makeNoise method -Animals.insert({ name: "raptor", sound: "roar" }); -Animals.findOne({ name: "raptor" }).makeNoise(); // prints "roar" +Animals.insert({name: "raptor", sound: "roar"}); +Animals.findOne({name: "raptor"}).makeNoise(); // prints "roar" + /** * From Collections, Collection.insert section */ // DA: I added the variable declaration statements to make this work var Lists = new Mongo.Collection('Lists'); var Items = new Mongo.Collection('Lists'); -var groceriesId = Lists.insert({ name: "Groceries" }); -Items.insert({ list: groceriesId, name: "Watercress" }); -Items.insert({ list: groceriesId, name: "Persimmons" }); + +var groceriesId = Lists.insert({name: "Groceries"}); +Items.insert({list: groceriesId, name: "Watercress"}); +Items.insert({list: groceriesId, name: "Persimmons"}); + /** * From Collections, collection.update section */ var Players = new Mongo.Collection('Players'); + Template['adminDashboard'].events({ 'click .givePoints': function () { - Players.update(Session.get("currentPlayer"), { $inc: { score: 5 } }); + Players.update(Session.get("currentPlayer"), {$inc: {score: 5}}); } }); + /** * Also from Collections, collection.update section */ Meteor.methods({ declareWinners: function () { - Players.update({ score: { $gt: 10 } }, { $addToSet: { badges: "Winner" } }, { multi: true }); + Players.update({score: {$gt: 10}}, + {$addToSet: {badges: "Winner"}}, + {multi: true}); } }); + /** * From Collections, collection.remove section */ @@ -188,57 +255,76 @@ Template['chat'].events({ Messages.remove(this._id); } }); + // DA: I added this next line var Logs = new Mongo.Collection('logs'); + Meteor.startup(function () { if (Meteor.isServer) { Logs.remove({}); - Players.remove({ karma: { $lt: -2 } }); + Players.remove({karma: {$lt: -2}}); } }); -Posts = new Mongo.Collection("posts"); + +/*** + * From Collections, collection.allow section + */ + +interface iPost { + _id: string; + owner: string; + userId: string; + locked: boolean; +} + +Posts = new Mongo.Collection("posts"); + Posts.allow({ - insert: function (userId, doc) { + insert: function (userId, doc: iPost) { // the user must be logged in, and the document must be owned by the user return (userId && doc.owner === userId); }, - update: function (userId, doc, fields, modifier) { + update: function (userId, doc: iPost, fields, modifier) { // can only change your own documents return doc.owner === userId; }, - remove: function (userId, doc) { + remove: function (userId, doc: iPost) { // can only remove your own documents return doc.owner === userId; }, fetch: ['owner'] }); + Posts.deny({ - update: function (userId, doc, fields, modifier) { + update: function (userId, doc: iPost, fields, modifier) { // can't change owners return doc.userId !== userId; }, - remove: function (userId, doc) { + remove: function (userId, doc: iPost) { // can't remove locked documents return doc.locked; }, fetch: ['locked'] // no need to fetch 'owner' }); + /** * From Collections, cursor.forEach section */ -var topPosts = Posts.find({}, { sort: { score: -1 }, limit: 5 }); +var topPosts = Posts.find({}, {sort: {score: -1}, limit: 5}); var count = 0; topPosts.forEach(function (post) { console.log("Title of post " + count + ": " + post.title); count += 1; }); + /** * From Collections, cursor.observeChanges section */ // DA: I added this line to make it work var Users = new Mongo.Collection('users'); + var count1 = 0; -var query = Users.find({ admin: true, onlineNow: true }); +var query = Users.find({admin: true, onlineNow: true}); var handle = query.observeChanges({ added: function (id, user) { count1++; @@ -249,38 +335,49 @@ var handle = query.observeChanges({ console.log("Lost one. We're now down to " + count1 + " admins."); } }); + // After five seconds, stop keeping the count. -setTimeout(function () { handle.stop(); }, 5000); +setTimeout(function () {handle.stop();}, 5000); + /** * From Sessions, Session.set section */ Tracker.autorun(function () { - Meteor.subscribe("chat-history", { room: Session.get("currentRoomId") }); + Meteor.subscribe("chat-history", {room: Session.get("currentRoomId")}); }); + // Causes the function passed to Tracker.autorun to be re-run, so // that the chat-history subscription is moved to the room "home". Session.set("currentRoomId", "home"); + /** * From Sessions, Session.get section */ // Page will say "We've always been at war with Eastasia" + // DA: commented out since transpiler didn't like append() //document.body.append(frag1); + // Page will change to say "We've always been at war with Eurasia" Session.set("enemy", "Eurasia"); + /** * From Sessions, Session.equals section */ var value; Session.get("key") === value; Session.equals("key", value); + /** * From Accounts, Meteor.users section */ Meteor.publish("userData", function () { - return Meteor.users.find({ _id: this.userId }, { fields: { 'other': 1, 'things': 1 } }); + return Meteor.users.find({_id: this.userId}, + {fields: {'other': 1, 'things': 1}}); }); -Meteor.users.deny({ update: function () { return true; } }); + +Meteor.users.deny({update: function () { return true; }}); + /** * From Accounts, Meteor.loginWithExternalService section */ @@ -290,6 +387,7 @@ Meteor.loginWithGithub({ if (err) Session.set('errorMessage', err.reason || 'Unknown error'); }); + /** * From Accounts, Accounts.ui.config section */ @@ -303,6 +401,7 @@ Accounts.ui.config({ }, passwordSignupFields: 'USERNAME_AND_OPTIONAL_EMAIL' }); + /** * From Accounts, Accounts.validateNewUser section */ @@ -315,10 +414,11 @@ Accounts.validateNewUser(function (user) { Accounts.validateNewUser(function (user) { return user.username !== "root"; }); + /** * From Accounts, Accounts.onCreateUser section */ -Accounts.onCreateUser(function (options, user) { +Accounts.onCreateUser(function(options, user) { var d6 = function () { return Math.floor(Math.random() * 6) + 1; }; user.dexterity = d6() + d6() + d6(); // We still want the default hook's 'profile' behavior. @@ -326,6 +426,7 @@ Accounts.onCreateUser(function (options, user) { user.profile = options.profile; return user; }); + /** * From Passwords, Accounts.emailTemplates section */ @@ -339,6 +440,7 @@ Accounts.emailTemplates.enrollAccount.text = function (user, url) { + " To activate your account, simply click the link below:\n\n" + url; }; + /** * From Templates, Template.myTemplate.helpers section */ @@ -351,33 +453,45 @@ Template['newTemplate'].helpers({ helperName: function () { } }); + Template['newTemplate'].created = function () { + }; + Template['newTemplate'].rendered = function () { + }; + Template['newTemplate'].destroyed = function () { + }; + Template['newTemplate'].events({ - 'click .something': function (event, template) { + 'click .something': function (event: Meteor.Event, template: Blaze.TemplateInstance) { } }); -Template.registerHelper('testHelper', function () { + +Template.registerHelper('testHelper', function() { return 'tester'; }); + var instance = Template.instance(); var data = Template.currentData(); var data = Template.parentData(1); var body = Template.body; + /** * From Match section */ var Chats = new Mongo.Collection('chats'); + Meteor.publish("chats-in-room", function (roomId) { // Make sure roomId is a string, not an arbitrary mongo selector object. check(roomId, String); - return Chats.find({ room: roomId }); + return Chats.find({room: roomId}); }); -Meteor.methods({ addChat: function (roomId, message) { + +Meteor.methods({addChat: function (roomId, message) { check(roomId, String); check(message, { text: String, @@ -385,31 +499,39 @@ Meteor.methods({ addChat: function (roomId, message) { // Optional, but if present must be an array of strings. tags: Match.Optional('Test String') }); + // ... do something with the message ... -} }); +}}); + /** * From Match patterns section */ var pat = { name: Match.Optional('test') }; -check({ name: "something" }, pat); // OK -check({}, pat); // OK -check({ name: undefined }, pat); // Throws an exception +check({ name: "something" }, pat) // OK +check({}, pat) // OK +check({ name: undefined }, pat) // Throws an exception + // Outside an object check(undefined, Match.Optional('test')); // OK + /** * From Deps, Tracker.autorun section */ Tracker.autorun(function () { var oldest = Monkeys.findOne('age = 20'); + if (oldest) Session.set("oldest", oldest.name); }); + Tracker.autorun(function (c) { - if (!Session.equals("shouldAlert", true)) + if (! Session.equals("shouldAlert", true)) return; + c.stop(); alert("Oh no!"); }); + /** * From Deps, Deps.Computation */ @@ -418,64 +540,84 @@ if (Tracker.active) { console.log('invalidated'); }); } + /** * From Tracker, Tracker.Dependency */ var weather = "sunny"; var weatherDep = new Tracker.Dependency; + var getWeather = function () { weatherDep.depend(); return weather; }; + var setWeather = function (w) { weather = w; // (could add logic here to only call changed() // if the new value is different from the old) weatherDep.changed(); }; + /** * From HTTP, HTTP.call section */ -Meteor.methods({ checkTwitter: function (userId) { +Meteor.methods({checkTwitter: function (userId) { check(userId, String); this.unblock(); - var result = HTTP.call("GET", "http://api.twitter.com/xyz", { params: { user: userId } }); + var result = HTTP.call("GET", "http://api.twitter.com/xyz", + {params: {user: userId}}); if (result.statusCode === 200) - return true; + return true return false; -} }); -HTTP.call("POST", "http://api.twitter.com/xyz", { data: { some: "json", stuff: 1 } }, function (error, result) { - if (result.statusCode === 200) { - Session.set("twizzled", true); - } -}); +}}); + + +HTTP.call("POST", "http://api.twitter.com/xyz", + {data: {some: "json", stuff: 1}}, + function (error, result) { + if (result.statusCode === 200) { + Session.set("twizzled", true); + } + }); + /** * From Email, Email.send section */ Meteor.methods({ sendEmail: function (to, from, subject, text) { check([to, from, subject, text], [String]); + // Let other method calls from the same client start running, // without waiting for the email sending to complete. this.unblock(); } }); + // In your client code: asynchronously send an email -Meteor.call('sendEmail', 'alice@example.com', 'Hello from Meteor!', 'This is a test of Email.send.'); +Meteor.call('sendEmail', + 'alice@example.com', + 'Hello from Meteor!', + 'This is a test of Email.send.'); + var testTemplate = new Blaze.Template(); var testView = new Blaze.View(); + +declare var el: HTMLElement; Blaze.render(testTemplate, el); -Blaze.renderWithData(testTemplate, { testData: 123 }, el); +Blaze.renderWithData(testTemplate, {testData: 123}, el); Blaze.remove(testView); Blaze.getData(el); Blaze.getData(testView); Blaze.toHTML(testTemplate); Blaze.toHTML(testView); -Blaze.toHTMLWithData(testTemplate, { test: 1 }); -Blaze.toHTMLWithData(testTemplate, function () { }); -Blaze.toHTMLWithData(testView, { test: 1 }); -Blaze.toHTMLWithData(testView, function () { }); -var reactiveVar1 = new ReactiveVar('test value'); -var reactiveVar2 = new ReactiveVar('test value', function (oldVal) { return true; }); -var varValue = reactiveVar1.get(); +Blaze.toHTMLWithData(testTemplate, {test: 1}); +Blaze.toHTMLWithData(testTemplate, function() {}); +Blaze.toHTMLWithData(testView, {test: 1}); +Blaze.toHTMLWithData(testView, function() {}); + +var reactiveVar1 = new ReactiveVar('test value'); +var reactiveVar2 = new ReactiveVar('test value', function(oldVal) { return true; }); + +var varValue: string = reactiveVar1.get(); reactiveVar1.set('new value'); diff --git a/meteor/meteor.d.ts b/meteor/meteor.d.ts index 54fe020b7..ee6c1db41 100644 --- a/meteor/meteor.d.ts +++ b/meteor/meteor.d.ts @@ -59,7 +59,7 @@ declare module Meteor { declare module DDP { interface DDPStatic { - subscribe(name: string, ...rest: any[]); + subscribe(name: string, ...rest: any[]): Meteor.SubscriptionHandle; call(method: string, ...parameters: any[]):void; apply(method: string, ...parameters: any[]):void; methods(IMeteorMethodsDictionary: any): any; @@ -290,8 +290,8 @@ interface MailComposerStatic { interface MailComposer { addHeader(name: string, value: string): void; setMessageOption(from: string, to: string, body: string, html: string): void; - streamMessage(); - pipe(stream: any /** fs.WriteStream **/); + streamMessage(): void; + pipe(stream: any /** fs.WriteStream **/): void; } /** * These are the modules and interfaces for packages that can't be automatically generated from the Meteor data.js file @@ -342,8 +342,8 @@ declare module Meteor { } declare module Accounts { - function addEmail(userId: string, newEmail: string, verified?: boolean); /** TODO: add return value **/ -function changePassword(oldPassword: string, newPassword: string, callback?: Function): void; + function addEmail(userId: string, newEmail: string, verified?: boolean): void; + function changePassword(oldPassword: string, newPassword: string, callback?: Function): void; function createUser(options: { username?: string; email?: string; @@ -359,23 +359,23 @@ function changePassword(oldPassword: string, newPassword: string, callback?: Fun function onEmailVerificationLink(callback: Function): void; function onEnrollmentLink(callback: Function): void; function onResetPasswordLink(callback: Function): void; - function removeEmail(userId: string, email: string); /** TODO: add return value **/ -function resetPassword(token: string, newPassword: string, callback?: Function): void; + function removeEmail(userId: string, email: string): void; + function resetPassword(token: string, newPassword: string, callback?: Function): void; function sendEnrollmentEmail(userId: string, email?: string): void; function sendResetPasswordEmail(userId: string, email?: string): void; function sendVerificationEmail(userId: string, email?: string): void; function setPassword(userId: string, newPassword: string, options?: { logout?: Object; }): void; - function setUsername(userId: string, newUsername: string); /** TODO: add return value **/ -var ui: { - config(options: { - requestPermissions?: Object; - requestOfflineToken?: Object; - forceApprovalPrompt?: Object; - passwordSignupFields?: string; - }): void; - }; + function setUsername(userId: string, newUsername: string): void; + var ui: { + config(options: { + requestPermissions?: Object; + requestOfflineToken?: Object; + forceApprovalPrompt?: Object; + passwordSignupFields?: string; + }): void; + }; function verifyEmail(token: string, callback?: Function): void; function config(options: { sendVerificationEmail?: boolean; @@ -383,39 +383,17 @@ var ui: { restrictCreationByEmailDomain?: string | Function; loginExpirationInDays?: number; oauthSecretKey?: string; - }); /** TODO: add return value **/ -function onLogin(func: Function); /** TODO: add return value **/ -function onLoginFailure(func: Function); /** TODO: add return value **/ -function user(); /** TODO: add return value **/ -function userId(); /** TODO: add return value **/ -function config(options: { - sendVerificationEmail?: boolean; - forbidClientAccountCreation?: boolean; - restrictCreationByEmailDomain?: string | Function; - loginExpirationInDays?: number; - oauthSecretKey?: string; -}); /** TODO: add return value **/ -function loggingIn(); /** TODO: add return value **/ -function logout(callback?: Function); /** TODO: add return value **/ -function logoutOtherClients(callback?: Function); /** TODO: add return value **/ -function onLogin(func: Function); /** TODO: add return value **/ -function onLoginFailure(func: Function); /** TODO: add return value **/ -function user(); /** TODO: add return value **/ -function userId(); /** TODO: add return value **/ -function config(options: { - sendVerificationEmail?: boolean; - forbidClientAccountCreation?: boolean; - restrictCreationByEmailDomain?: string | Function; - loginExpirationInDays?: number; - oauthSecretKey?: string; -}); /** TODO: add return value **/ -function onCreateUser(func: Function); /** TODO: add return value **/ -function onLogin(func: Function); /** TODO: add return value **/ -function onLoginFailure(func: Function); /** TODO: add return value **/ -function user(); /** TODO: add return value **/ -function userId(); /** TODO: add return value **/ -function validateLoginAttempt(func: Function); /** TODO: add return value **/ -function validateNewUser(func: Function); /** TODO: add return value **/ + }): void; + function onLogin(func: Function): { stop: () => void }; + function onLoginFailure(func: Function): { stop: () => void }; + function user(): Meteor.User; + function userId(): string; + function loggingIn(): boolean; + function logout(callback?: Function): void; + function logoutOtherClients(callback?: Function): void; + function onCreateUser(func: Function): void; + function validateLoginAttempt(func: Function): { stop: () => void }; + function validateNewUser(func: Function): boolean; } declare module App { @@ -636,8 +614,8 @@ declare module Mongo { transform?: Function; }): T; insert(doc: T, callback?: Function): string; - rawCollection(); /** TODO: add return value **/ - rawDatabase(); /** TODO: add return value **/ + rawCollection(): any; + rawDatabase(): any; remove(selector: Mongo.Selector | Mongo.ObjectID | string, callback?: Function): void; update(selector: Mongo.Selector | Mongo.ObjectID | string, modifier: Mongo.Modifier, options?: { multi?: boolean; @@ -808,7 +786,7 @@ interface PackageAPIStatic { new(): PackageAPI; } interface PackageAPI { - addAssets(filenames: string | string[], architecture: string | string[]); /** TODO: add return value **/ + addAssets(filenames: string | string[], architecture: string | string[]): void; addFiles(filenames: string | string[], architecture?: string | string[], options?: { bare?: boolean; }): void;