typescript 打字稿 | 模块没有导出成员

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41861948/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:33:33  来源:igfitidea点击:

TypeScript | Module has no exported member

typescriptimport

提问by Matthew Layton

Following these quite basic instructions, but this seems not to work.

遵循这些非常基本的说明,但这似乎不起作用。

https://stackoverflow.com/a/35894727/1033686

https://stackoverflow.com/a/35894727/1033686

Overview

概述

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

我想用import { Type } from "Module"而不是/// <reference path="..." />

Structure

结构

-app\
  -ViewModel.ts
  -Program.ts

ViewModel.ts

视图模型.ts

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

Program.ts

程序.ts

import { ViewModel } from "ViewModel";

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

模块“C:/DemoApp/app/ViewModel”没有导出成员“ViewModel”。

and...

和...

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

仅支持 'amd' 和 'system' 模块与 --outFile 一起使用。

Goal

目标

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

我希望能够引用依赖项,以便它们按顺序编译为单个文件。

Please help!

请帮忙!

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

注意:如果我添加,"module": "system"我仍然会遇到上述错误中的第一个。

Note:As per the 1st solution, I do not want to lose namespaces!

注意:根据第一个解决方案,我不想丢失命名空间!

采纳答案by Ali Baig

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) {
        }
    }
}