Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 578
Matthew Layton Avatar asked Jan 25 '17 21:01

Matthew Layton


People also ask

How do I export a function in TypeScript?

Use named exports to export a function in TypeScript, e.g. export function sum() {} . The exported function can be imported by using a named import as import {sum} from './another-file' . You can use as many named exports as necessary in a single file.

How do I export a TypeScript Const?

To export a constant in TypeScript, we can use the export keyword. export const adminUser = { //... }; to export the adminUser constant.

What is export type in TypeScript?

TypeScript supports export = to model the traditional CommonJS and AMD workflow. The export = syntax specifies a single object that is exported from the module. This can be a class, interface, namespace, function, or enum.

What is declare module in TypeScript?

The TypeScript declares module is one of the modules and keyword it is used for to surround and define the classes, interfaces; variables are also declared it will not originate with the TypeScript like that module is the set of files that contains values, classes, functions/methods, keywords, enum all these contains ...


1 Answers

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) {         }     } } 
like image 107
Ali Baig Avatar answered Sep 21 '22 04:09

Ali Baig