【问题标题】:How to solve the "module has no exported member" error?如何解决“模块没有导出成员”错误?
【发布时间】:2017-06-11 05:52:23
【问题描述】:

我正在遵循the this answer 的指示,但无法使解决方案发挥作用。

概述

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

结构

-app\
  -ViewModel.ts
  -Program.ts

ViewModel.ts

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

Program.ts

import { ViewModel } from "ViewModel";

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

还有……

仅支持“amd”和“system”模块以及 --outFile。

目标

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


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

根据第一种解决方案,我不想丢失命名空间。

【问题讨论】:

标签: typescript es6-modules


【解决方案1】:

从您的陈述中删除以下行

export module Demo

并像使用它一样

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

编辑:对于命名空间,只需执行类似

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

【讨论】:

【解决方案2】:

一个原因可能是拼写错误。

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

export const Demo =()=> () can be exported without return.

【讨论】:

    猜你喜欢
    • 2017-03-29
    • 1970-01-01
    • 2021-11-07
    • 1970-01-01
    • 2019-12-05
    • 1970-01-01
    • 1970-01-01
    • 2021-09-09
    相关资源
    最近更新 更多