mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Updated for Meteor version 1.1.0.1
This commit is contained in:
+18
-20
@@ -1,6 +1,6 @@
|
||||
# Meteor Type Definitions
|
||||
|
||||
These are the definitions for version 1.0.3.1 of Meteor.
|
||||
These are the definitions for version 1.1.0.1 of Meteor.
|
||||
|
||||
Although these definitions can be downloaded separately for use, the recommended way to use these definitions in a Meteor application is by installing the
|
||||
[typescript-libs](https://atmospherejs.com/meteortypescript/typescript-libs) Meteor smart package from atmosphere. The smart package contains TypeScript
|
||||
@@ -16,25 +16,21 @@ to generate the official [Meteor docs] (http://docs.meteor.com/).
|
||||
|
||||
## Usage
|
||||
|
||||
1. If you are using the smart package, add a symbolic link to the definitions from within some directory within your project (e.g. ".typescript" or "lib"). The
|
||||
definitions can be found somewhere deep within `<project_root_dir>/.meteor/...`. The following will probably work:
|
||||
1. Add a symbolic link to the definitions from within some directory within your project (e.g. ".typescript" or "lib"). The definitions can be found somewhere
|
||||
deep within `<project_root_dir>/.meteor/...`. The following will probably work:
|
||||
|
||||
$ ln -s ../.meteor/local/build/programs/server/assets/packages/meteortypescript_typescript-libs/definitions package_defs
|
||||
|
||||
|
||||
If the definitions can't be found within the .meteor directory, you will have to manually pull down the definitions from github and add them to your project:
|
||||
<https://github.com/meteor-typescript/meteor-typescript-libs>
|
||||
|
||||
If you are just using the *meteor.d.ts* file from this source, you can just add the file to any directory in your project (e.g. ".typescript" or "lib").
|
||||
|
||||
2. Install the [Typescript compiler for Meteor](https://github.com/meteor-typescript/meteor-typescript-compiler) or an [IDE which can transpile TypeScript to JavaScript](#transpiling-typescript).
|
||||
3. From the typescript files, add references. Reference the definition files with a single line:
|
||||
|
||||
/// <reference path=".typescript/package_defs/all-definitions.d.ts" /> (substitute path in your project)
|
||||
|
||||
|
||||
Or you can reference definition files individually:
|
||||
|
||||
|
||||
/// <reference path=".typescript/package_defs/meteor.d.ts" /> (substitue path in your project)
|
||||
/// <reference path=".typescript/package_defs/underscore.d.ts" />
|
||||
/// <reference path=".typescript/package_defs/jquery.d.ts" />
|
||||
@@ -46,26 +42,28 @@ definitions can be found somewhere deep within `<project_root_dir>/.meteor/...`.
|
||||
|
||||
### References
|
||||
|
||||
Try to stay away from referencing *file.ts*, rather generate a *file.d.ts* using `tsc --reference file.ts`, and reference it in your file. Compilation will
|
||||
be much faster and code cleaner - it's always better to split definition from implemention.
|
||||
Meteor code can run on the client and the server, for this reason you should try to stay away from referencing *file.ts* directly: you may get unexpected results.
|
||||
Rather generate a *file.d.ts* using `tsc --reference file.ts`, and reference it in your file.
|
||||
|
||||
Compilation will be much faster and code cleaner - it's always better to split definition from implementation anyways.
|
||||
|
||||
### Templates
|
||||
|
||||
When specifying template *helpers*, *events*, and functions for *created*, *rendered*, and *destroyed*, you will need to use a "bracket notation" instead of the "dot notation":
|
||||
With the exception of the **body** and **head** templates, Meteor's Template dot notation cannot be used (ie. *Template.mytemplate*). Thanks to Typescript static typing checks, you will need to used the *bracket notation* to access the Template.
|
||||
|
||||
Template['myTemplateName']['helpers']({
|
||||
|
||||
Template['myTemplateName'].helpers({
|
||||
foo: function () {
|
||||
return Session.get("foo");
|
||||
}
|
||||
});
|
||||
|
||||
Template['myTemplateName']['rendered'] = function ( ) { ... }
|
||||
Template['myTemplateName'].rendered = function ( ) { ... }
|
||||
|
||||
|
||||
This is because TypeScript enforces typing and it will throw an error saying "myTemplateName" does not exist when using the dot notation.
|
||||
### Form fields
|
||||
|
||||
### Accessing a Form field
|
||||
|
||||
Trying to read a form field value? use `(<HTMLInputElement>evt.target).value`.
|
||||
Form fields typically need to be casted to <HTMLInputElement>. For instance to read a form field value, use `(<HTMLInputElement>evt.target).value`.
|
||||
|
||||
### Global variables
|
||||
|
||||
@@ -77,7 +75,7 @@ Preface any global variable declarations with a TypeScript "declare var" stateme
|
||||
|
||||
### Collections
|
||||
|
||||
The majority of extra work required to use TypeScript with Meteor is creating and maintaining the collection interfaces. However, doing so also provides the
|
||||
The majority of extra work required to use TypeScript with Meteor is creating and maintaining the collection interfaces. However, doing so also provides the
|
||||
additional benefit of succinctly documenting collection schema definitions (that are actually enforced).
|
||||
|
||||
To define collections, you will need to create an interface representing the collection and then declare a Collection type variable with that interface type (as a generic):
|
||||
@@ -113,7 +111,7 @@ for all of you custom definitions. e.g. contents of ".typescript/custom_defs/cu
|
||||
/// <reference path='paraview_helpers.d.ts'/>
|
||||
/// <reference path='handsontable.d.ts'/>
|
||||
/// <reference path='utility_helpers.ts'/>
|
||||
|
||||
|
||||
|
||||
## Transpiling TypeScript
|
||||
|
||||
@@ -132,4 +130,4 @@ Then, within WebStorm, go to Preferences -> File Watchers -> "+" symbol and add
|
||||
|
||||
Last option, is to compile code from the command line. With node and the typescript compiler installed:
|
||||
|
||||
$ tsc *.ts
|
||||
$ tsc *.ts
|
||||
|
||||
+80
-52
@@ -8,21 +8,15 @@
|
||||
|
||||
|
||||
/*********************************** Begin setup for tests ******************************/
|
||||
|
||||
// A developer must declare a var Template like this in a separate file to use this TypeScript type definition file
|
||||
//interface ITemplate {
|
||||
// adminDashboard: Meteor.Template;
|
||||
// chat: Meteor.Template;
|
||||
//}
|
||||
//declare var Template: ITemplate;
|
||||
|
||||
var Rooms = new Mongo.Collection('rooms');
|
||||
var Messages = new Mongo.Collection('messages');
|
||||
var Monkeys = new Mongo.Collection('monkeys');
|
||||
var x = new Mongo.Collection('x');
|
||||
var y = new Mongo.Collection('y');
|
||||
|
||||
var check = function(str1, str2) {};
|
||||
interface MonkeyDAO {
|
||||
_id: string;
|
||||
name: string;
|
||||
}
|
||||
var Monkeys = new Mongo.Collection<MonkeyDAO>('monkeys');
|
||||
//var x = new Mongo.Collection<xDAO>('x');
|
||||
//var y = new Mongo.Collection<yDAO>('y');
|
||||
/********************************** End setup for tests *********************************/
|
||||
|
||||
|
||||
@@ -98,8 +92,8 @@ Tracker.autorun(function () {
|
||||
});
|
||||
|
||||
console.log("Current room has " +
|
||||
Counts.find(Session.get("roomId")).count +
|
||||
" messages.");
|
||||
Counts.find(Session.get("roomId")).count +
|
||||
" messages.");
|
||||
|
||||
/**
|
||||
* From Publish and Subscribe, Meteor.subscribe section
|
||||
@@ -124,7 +118,7 @@ Meteor.methods({
|
||||
|
||||
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");
|
||||
throw new Meteor.Error("404", "Can't find my pants");
|
||||
return "some return value";
|
||||
},
|
||||
|
||||
@@ -146,15 +140,15 @@ var result = Meteor.call('foo', 1, 2);
|
||||
// DA: I added the "var" keyword in there
|
||||
|
||||
interface ChatroomsDAO {
|
||||
_id?: string;
|
||||
_id?: string;
|
||||
}
|
||||
interface MessagesDAO {
|
||||
_id?: string;
|
||||
_id?: string;
|
||||
}
|
||||
var Chatrooms = new Mongo.Collection<ChatroomsDAO>("chatrooms");
|
||||
Messages = new Mongo.Collection<MessagesDAO>("messages");
|
||||
|
||||
var myMessages = Messages.find({userId: Session.get('myUserId')}).fetch();
|
||||
var myMessages = <MessagesDAO> Messages.find({userId: Session.get('myUserId')}).fetch();
|
||||
|
||||
Messages.insert({text: "Hello, world!"});
|
||||
|
||||
@@ -171,10 +165,10 @@ Posts.insert({title: "Hello world", body: "First post"});
|
||||
* since there is already a Collection constructor with a different signature
|
||||
*
|
||||
var Scratchpad = new Mongo.Collection;
|
||||
for (var i = 0; i < 10; i++)
|
||||
Scratchpad.insert({number: i * 2});
|
||||
assert(Scratchpad.find({number: {$lt: 9}}).count() === 5);
|
||||
**/
|
||||
for (var i = 0; i < 10; i++)
|
||||
Scratchpad.insert({number: i * 2});
|
||||
assert(Scratchpad.find({number: {$lt: 9}}).count() === 5);
|
||||
**/
|
||||
|
||||
var Animal = function (doc) {
|
||||
// _.extend(this, doc);
|
||||
@@ -185,11 +179,16 @@ Animal.prototype = {
|
||||
makeNoise: function () {
|
||||
console.log(this.sound);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
interface AnimalDAO {
|
||||
_id: string;
|
||||
makeNoise: () => void;
|
||||
}
|
||||
|
||||
|
||||
// Define a Collection that uses Animal as its document
|
||||
var Animals = new Mongo.Collection("Animals", {
|
||||
var Animals = new Mongo.Collection<AnimalDAO>("Animals", {
|
||||
transform: function (doc) { return new Animal(doc); }
|
||||
});
|
||||
|
||||
@@ -225,8 +224,8 @@ Template['adminDashboard'].events({
|
||||
Meteor.methods({
|
||||
declareWinners: function () {
|
||||
Players.update({score: {$gt: 10}},
|
||||
{$addToSet: {badges: "Winner"}},
|
||||
{multi: true});
|
||||
{$addToSet: {badges: "Winner"}},
|
||||
{multi: true});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -348,7 +347,7 @@ Session.equals("key", value);
|
||||
*/
|
||||
Meteor.publish("userData", function () {
|
||||
return Meteor.users.find({_id: this.userId},
|
||||
{fields: {'other': 1, 'things': 1}});
|
||||
{fields: {'other': 1, 'things': 1}});
|
||||
});
|
||||
|
||||
Meteor.users.deny({update: function () { return true; }});
|
||||
@@ -412,8 +411,8 @@ Accounts.emailTemplates.enrollAccount.subject = function (user) {
|
||||
};
|
||||
Accounts.emailTemplates.enrollAccount.text = function (user, url) {
|
||||
return "You have been selected to participate in building a better future!"
|
||||
+ " To activate your account, simply click the link below:\n\n"
|
||||
+ url;
|
||||
+ " To activate your account, simply click the link below:\n\n"
|
||||
+ url;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -424,6 +423,36 @@ Template['adminDashboard'].helpers({
|
||||
return Session.get("foo");
|
||||
}
|
||||
});
|
||||
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.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
|
||||
@@ -481,10 +510,9 @@ Tracker.autorun(function (c) {
|
||||
* From Deps, Deps.Computation
|
||||
*/
|
||||
if (Tracker.active) {
|
||||
Tracker.onInvalidate(function () {
|
||||
x.destroy();
|
||||
y.finalize();
|
||||
});
|
||||
Tracker.onInvalidate(function () {
|
||||
console.log('invalidated');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -494,15 +522,15 @@ var weather = "sunny";
|
||||
var weatherDep = new Tracker.Dependency;
|
||||
|
||||
var getWeather = function () {
|
||||
weatherDep.depend();
|
||||
return weather;
|
||||
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();
|
||||
weather = w;
|
||||
// (could add logic here to only call changed()
|
||||
// if the new value is different from the old)
|
||||
weatherDep.changed();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -512,7 +540,7 @@ Meteor.methods({checkTwitter: function (userId) {
|
||||
check(userId, String);
|
||||
this.unblock();
|
||||
var result = HTTP.call("GET", "http://api.twitter.com/xyz",
|
||||
{params: {user: userId}});
|
||||
{params: {user: userId}});
|
||||
if (result.statusCode === 200)
|
||||
return true
|
||||
return false;
|
||||
@@ -520,12 +548,12 @@ Meteor.methods({checkTwitter: function (userId) {
|
||||
|
||||
|
||||
HTTP.call("POST", "http://api.twitter.com/xyz",
|
||||
{data: {some: "json", stuff: 1}},
|
||||
function (error, result) {
|
||||
if (result.statusCode === 200) {
|
||||
Session.set("twizzled", true);
|
||||
}
|
||||
});
|
||||
{data: {some: "json", stuff: 1}},
|
||||
function (error, result) {
|
||||
if (result.statusCode === 200) {
|
||||
Session.set("twizzled", true);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* From Email, Email.send section
|
||||
@@ -542,9 +570,9 @@ Meteor.methods({
|
||||
|
||||
// In your client code: asynchronously send an email
|
||||
Meteor.call('sendEmail',
|
||||
'alice@example.com',
|
||||
'Hello from Meteor!',
|
||||
'This is a test of Email.send.');
|
||||
'alice@example.com',
|
||||
'Hello from Meteor!',
|
||||
'This is a test of Email.send.');
|
||||
|
||||
var testTemplate = new Blaze.Template();
|
||||
var testView = new Blaze.View();
|
||||
@@ -562,8 +590,8 @@ 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 reactiveVar1 = new ReactiveVar<string>('test value');
|
||||
var reactiveVar2 = new ReactiveVar<string>('test value', function(oldVal) { return true; });
|
||||
|
||||
var varValue: string = reactiveVar1.get();
|
||||
reactiveVar1.set('new value');
|
||||
Vendored
+638
-538
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user