35

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.

Matthew Layton
  • 39,871
  • 52
  • 185
  • 313
  • Possible duplicate: http://stackoverflow.com/questions/30357634/how-do-i-use-namespaces-with-typescript-external-modules – artem Jan 25 '17 at 21:55

3 Answers3

22

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) {
        }
    }
}
Ali Baig
  • 3,819
  • 4
  • 34
  • 47
  • I've updated my answer, see if it works now. Read more about it here: https://www.typescriptlang.org/docs/handbook/namespaces-and-modules.html – Ali Baig Jan 25 '17 at 21:43
  • When I do this I get the error File 'pathtofile' is not a module – greg Jul 14 '18 at 17:32
0

One reason can be typo.

export const Demo = () => {} cannot be exported if it does not return a value.

export const Demo =()=> () can be exported without return.
AhuraMazda
  • 460
  • 4
  • 22
-2

May not be or check the module which you're using there.

export a () => {
   console.log("Hello world!");
}
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Goutham J.M Jul 28 '22 at 09:10
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/32335431) – Elliot Plant Jul 29 '22 at 22:04