[Fixed] angular2 meteor ionic – cannot use namespace Observable as a type


I’m following this tutorial trying my best not to hate angular with all my being. The tutorial uses Typescript and Angular2 and Ionic, 3 tools which I don’t entirely understand, but that’s like… why I’m doing a tutorial in the first place. My experience in web development was 2.0 with Django, and a lot of front-end so I know Javascript very well, but this is confusing me.

This is the relevant code:

// chats.ts
import { Component } from '@angular/core';
import * as Moment from 'moment';
import { Observable } from 'rxjs/Observable';
import { Chat, MessageType } from '../../../../imports/models';

import template from './chats.html';


export class ChatsPage {
    chats: Observable<Chat[]>;

    constructor() {
        this.chats = this.findChats();

    private findChats(): Observable<Chat[]> {
        return Observable.of([
                _id: '0',
                title: 'Ethan Gonzalez',
                picture: 'https://randomuser.me/api/portraits/thumb/men/1.jpg',
                lastMessage: {
                  content: 'You on your way?',
                  createdAt: Moment().subtract(1, 'hours').toDate(),
                  type: MessageType.TEXT
     // dummy data here

Second file:

// app.components.ts

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';
import { ChatsPage } from '../pages/chats/chats';
import template from "./app.html";


export class MyApp {
    rootPage = ChatsPage;

    constructor(platform: Platform) {
        platform.ready().then(() => {
            if (platform.is('cordova')) {

When I run Meteor I get these errors:

client/imports/pages/chats/chats.ts (13, 12): Cannot use namespace 'Observable' as a type.
client/imports/pages/chats/chats.ts (19, 26): Cannot use namespace 'Observable' as a type.
client/imports/app/app.components.ts (14, 27): Cannot use namespace 'Platform' as a type.


FWIW at this point: I can reproduce the original errors when I don’t have the node_modules installed. And even after I install them, it looks like the barbatus:typescript build plugin is buggy and doesn’t invalidate its cache, so it still shows the original errors. If I delete .meteor/local/.typescript-cache, then the installed node_modules are recognized. In general I don’t trust barbatus:typescript (it tries to be clever and does too much complex stuff that ends up causing problems), but I don’t have an alternative that I can recommend for general use at this point. If you like, you could file an issue and see if barbatus will address this particular problem.

The Cannot use namespace ... as a type error seems to be a consequence of your declarations.d.ts file doing declare module '*';. The error doesn’t make sense to me, so I filed a TypeScript issue.

Leave a Reply

(*) Required, Your email will not be published