Skip to main content
The typescript package provides TypeScript support in Meteor applications, compiling .ts and .tsx files to JavaScript.

Installation

Overview

The typescript package provides:
  • TypeScript Compilation - Compile .ts and .tsx files
  • Type Checking - Static type checking during development
  • React Support - TSX for React components
  • Babel Integration - Combined with ECMAScript features
  • Source Maps - Debug original TypeScript source
  • Fast Refresh - Hot reloading for React components

Package Information

  • Version: 5.9.3
  • Summary: Compiler plugin that compiles TypeScript and ECMAScript in .ts and .tsx files
  • Dependencies: babel-compiler, babel-runtime, modules, ecmascript-runtime, promise, dynamic-import
  • Dev Only: true (compilation happens at build time)

Getting Started

Basic TypeScript File

Collection with Types

TypeScript Configuration

tsconfig.json

Create tsconfig.json in your project root:

Type Definitions

Install Meteor Types

Using Meteor Types

Custom Type Definitions

React with TypeScript

Functional Component

Component with State

Meteor Methods with Types

Define Method Types

Call Methods with Type Safety

Publications with Types

Generic Types

Utility Types

Async/Await with Types

Enums and Const Assertions

Best Practices

Enable strict mode - Use "strict": true in tsconfig.json
Define interfaces for documents - Create types for all collection documents
Type method parameters and returns - Explicit types for all methods
Use generics - Make reusable typed utilities

Common Issues

Module Resolution

If imports aren’t working:

Missing Types

ecmascript

ES2015+ JavaScript support

babel-compiler

Babel compilation engine

Source Code