Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在TypeScript中将类转换为模块_Javascript_Typescript - Fatal编程技术网

Javascript 在TypeScript中将类转换为模块

Javascript 在TypeScript中将类转换为模块,javascript,typescript,Javascript,Typescript,我有一门课: class Dice { div: Element; value: string; constructor(div: Element) { this.div = div; } } 我有dicerroller类扩展了Dice类: class diceRoller extends Dice { static Values = Values; constructor(div: Element) { supe

我有一门课:

class Dice {
    div: Element;
    value: string;
    constructor(div: Element) {
        this.div = div;
    }
}
我有
dicerroller
类扩展了
Dice
类:

class diceRoller extends Dice {
    static Values = Values;
    constructor(div: Element) {
        super(div);
        (this.div as HTMLElement).style.width = diceSize;
        (this.div as HTMLElement).style.height = diceSize;
        (this.div as HTMLElement).style.textAlign = 'center';
        (this.div as HTMLElement).style.lineHeight = diceSize;
        (this.div as HTMLElement).style.border = diceBorder;
        (this.div as HTMLElement).style.marginRight = '10px';
        (this.div as HTMLElement).style.cssFloat = 'left';
    }
    changeValue(val: number): boolean {
        this.value = Values[val];
        (this.div as HTMLElement).innerHTML = this.value;
        return true;
    }
}
如何将
类转化为模块。我已经在打字本手册中尝试了所有的方法,但我还没有弄明白


我想以类似于export{new diceRoller(div:Element)}的形式导出类,因为我想在导入模块的文件中向类传递一个参数。那么,具体的形式是什么

简单地说:

export const foo = new diceRoller(div);

我想以类似于export{new diceRoller(div:Element)}的形式导出类,因为我想在导入模块的文件中向类传递一个参数。那么,具体的形式是什么

简单地说:

export const foo = new diceRoller(div);

只需将其导出即可<代码>导出类diceRoller…
导出类Dice…
我想以类似于导出
{new diceRoller(div:Element)}
的形式导出类,因为我想在导入模块的文件中向类传递一个参数。那么,具体的形式是什么呢?只需将其导出即可<代码>导出类diceRoller…和
导出类Dice…
我想以类似于导出
{new diceRoller(div:Element)}
的形式导出类,因为我想在导入模块的文件中向类传递一个参数。那么,确切的形式是什么呢?非常感谢,我自己弄明白了。我只是在类之前添加了
export default
,我试图使用您的解决方案,但是TypeScript在参数
div
上标记了一个错误:
找不到名称“div”
非常感谢,我自己找到了答案。我只是在类之前添加了
export default
,我试图使用您的解决方案,但TypeScript在参数
div
上标记了一个错误:
找不到名称“div”