Search code examples
typescriptes6-modules

How to solve the "module has no exported member" error?


I am following instructions from the this answer, but cannot make the solution work.

Overview

I want to use import { Type } from "Module" instead of /// <reference path="..." />

Structure

-app\
  -ViewModel.ts
  -Program.ts

ViewModel.ts

export module Demo {
    export class ViewModel {
        constructor(public test: string) {
        }
    }
}

Program.ts

import { ViewModel } from "ViewModel";

Module 'C:/DemoApp/app/ViewModel' has no exported member 'ViewModel'.

and...

Only 'amd' and 'system' modules are supported alongside --outFile.

Goal

I want to be able to reference dependencies so that they compile to a single file in order.


If I add "module": "system" I still get the 1st of the aforementioned errors.

As per the 1st solution, I do not want to lose namespaces.


Solution

  • Remove the line below from your statement

    export module Demo
    

    and use it like

    export class ViewModel {
        constructor(public test: string) {
        }
    }
    

    Edit: For namespace, just do something like

    namespace Demo {
      export class ViewModel {
            constructor(public test: string) {
            }
        }
    }