barbatus:typescript

v0.7.0Published 6 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

TypeScript Compiler for Meteor

TypeScript files are compiled into ES5 and CommonJS modules by default.

Based on TypeScript@2.8.3

Default compiler options as JSON:

1{
2  "module": "commonjs",
3  "target": "es5",
4  "moduleResolution": "node",
5  "experimentalDecorators": true,
6  "emitDecoratorMetadata": true,
7  "sourceMap": true
8}

ES6

It's possible to use ES6 on the server with Meteor >= 1.4.

If you want to compile into ES6 on the server, put a tsconfig.json into the server folder:

1{
2  "compilerOptions": {
3    "target": "ES6"
4  }
5}

Path mappings

TypeScript paths mapping is supported since 0.6.0, though, with some limitations. It works only for local files and for module: commonjs.

You can now use paths like imports/client/foo instead of Meteor rooted paths like /imports/client/foo if you add to the config.json as follows:

1  "baseUrl": ".",
2  "paths": {
3    "*": ["*"]
4  }

Typings

Install Meteor typings by npm i @types/meteor and you are ready to go.

Custom Typings

Typings files are processed in the same way as regular ts-files. If you place a declaration file into server folder it will be used only for the server code only.

Note that any change to a global declaration file will cause diagnostics re-evaluation. Hence, if you change some custom declaration file often, makes sence to reference it in some main ts-file and exclude in the config, i.e.:

1 /// <reference path="typings/foo.d.ts" />
1{
2  "exclude": ["typings/foo.d.ts"]
3}

Example

As an example, check out a simple TODO app built with Angular2 and TypeScript, https://github.com/Urigo/angular-meteor/tree/master/examples/todos-meteor-1.3

Package Structure

This package uses (directly or indirectly) three other packages, which are worth to mention:

typescript-compiler - exports a Meteor TypeScript compiler that implements Meteor compiler API. TypeScript compiler in its turn uses meteor-typescript package’s API to compile TypeScript source code incrementally on file changes.

meteor-typescript - an NPM package that exports an incremental TypeScript build class. That class is designed to be used in the series of subsequent compilations of TypeScript source code. In that case, TypeScript Service API, which is used internally, allows to reuse compilation statistics and data between subsequent builds, thus, improving speed of the compilation.

typescript-runtime - currently contains TypeScript helpers, which allow to configure behavior of some parts of the compiled TypeScript code for special use cases. One of the use cases is usage with the old browsers.

Credits

Thanks @urigo (Uri) for his support and resources to continue development of this project.

License

MIT