TypeScript is cool, if your IDE supports its type-awareness. I tried Webstorm, but this IDE was way to slow for me. So I ditched it, and Atom is not really an IDE.
Babel is based on the ECMAScript standard, whereas TypeScript is somewhat proprietary. Good, but still proprietary. And with these languages, you never know where they are heading at in the future. Same goes for CoffeeScripts. So I decided to stick to standard tech, even if it’s not as nice as TypeScript.
@rhywden I have been meaning to give that a stab sooner or later but I could not find a concise yet complete overview of the whole meteor typescript experience.
It sounds like you are using it in production. So would you mind sharing your overall experience, perhaps along with some pointers, gotchas, goodies etc?
Then port some server only imports folder to npm package, written in TS.
This way Meteor doesn’t know about typescript, you can practice safely with the language, and you focus your effort where it is most effective, as server side code usually holds the biggest cognitive complexity.
Edit:
Thank you for those links and especially pointer 3!
Although, I’m kind of interested in typescript mileage strictly within Meteor projects. Meteor has globals, symbols hidden away in core or atmosphere packages, methods etc.
and then simply begin to use Typescript. Using React is also possible and only needs a single entry in a config file.
If you want to use Meteor stuff with typescript, you need definition files. You could, of course, write those yourself but no one does that.
There are three ways to get such definition files (besides rolling your own):
a) Use npm - you simply do this: npm install --save react @types/react
b) Use typings - that’s a helper program which pulls down definitions from several sources (like npm or DefinitelyTyped)
You can search for definitions with typings search react and then install them with typings install --save --global dt~react
The dt~ part indicates the source - if you want npm sources you do npm~
Install typings through npm install -g typings
c) If no such file exists, then you can do the following for npm-modules:
which will automatically create a typings file for you (however, most types will be defined as any)
If you don’t want to do all that you can also always do: declare module "foo"; which short-circuits TypeScript and lets you write anything, basically.
What you shouldn’t do: Mix the @types/module and typings methods - both can have different update levels which can lead to new and interesting problems.
But from my experience the npm sources seem to have issues which sometimes result in either something breaking (when you mix dt~ and npm~) or at least give you an annoying warning every time there’s a reload even though your code is perfectly fine.
Well that’s certainly immensely helpful, thank you for sharing it. I will certainly give it a shot.
Edit:
I’ve took a peek at it and I like what I see. I was kind of reluctant about setting this thing up for the client and thinking I would be better of with typescript on the backend and not the ui, but it seems it is not that scary and might indeed even be quite helpful. Thank you for this.
I’ll now risk acting like a spoiled child here and go ahead and ask you if you also have something of a boilerplate for the backend as well? You know with the usual suspects such as a collection, a, schema, publication, method etc.
I’m probably a little more curious about schemas if anything. I’m now
pondering a proper ORM (something similar to astronomy but based on simple
schema validations) and how typescript would fit into that picture.
Probably well, but I’m also probably overthinking.
In case you’re interested in using alanning:roles, this is the definitions file I just whipped up. No guarantees, but it should work.
declare module Roles {
function addUsersToRoles(users:string|Array<string>, roles:string|Array<string>,group?:string):void;
function createRole(role:string):string;
function deleteRole(role:string):void;
function getAllRoles(): Mongo.Cursor<{}>;
function getGroupsForUser(user:string|Meteor.User, role?:string):Array<string>;
function getRolesForUser(user:string|Meteor.User, group?:string):Array<string>;
function getUsersInRole(role:string|Array<string>, group?:string, options?:any): Mongo.Cursor<{}>;
function removeUsersFromRoles(users:string|Array<{_id:string}>|Array<Meteor.User>, roles:string|Array<string>, group?:string);
function setUserRoles (users:string|Array<{_id:string}>|Array<Meteor.User>, roles:string|Array<string>, group?:string );
function userIsInRole(user_id:string, role: string, group?:string): boolean;
}
declare module "meteor/alanning:roles" {
module Roles {
function addUsersToRoles(users:string|Array<string>, roles:string|Array<string>,group?:string):void;
function createRole(role:string):string;
function deleteRole(role:string):void;
function getAllRoles(): Mongo.Cursor<{}>;
function getGroupsForUser(user:string|Meteor.User, role?:string):Array<string>;
function getRolesForUser(user:string|Meteor.User, group?:string):Array<string>;
function getUsersInRole(role:string|Array<string>, group?:string, options?:any): Mongo.Cursor<{}>;
function removeUsersFromRoles(users:string|Array<{_id:string}>|Array<Meteor.User>, roles:string|Array<string>, group?:string);
function setUserRoles (users:string|Array<{_id:string}>|Array<Meteor.User>, roles:string|Array<string>, group?:string );
function userIsInRole(user_id:string, role: string, group?:string): boolean;
}
}
simply include that as, for example, alanning-roles.d.ts somewhere in /imports
Now I just have to see who I have to talk to to get that included into DefinitelyTyped or something.
I remember a discussion here on the forums to start a community effort to get meteor related type definitions into a common repo or wherever they are publicly shared. Hmm…