Typescript: 扩展外部模块

创建于 2014-11-28  ·  3评论  ·  资料来源: microsoft/TypeScript

我正在尝试扩展外部节点模块:

// a) Use an import?
import System.Fs.Node = require('fs');

// b) Hackery? 
var System = System || {}
var System.Fs = System.Fs || {}
var System.Fs.Node = require('fs')

module System.Fs.Node {

    var path = require('path');

    interface IfOptions_mkdir {
        mode?: number
        recursive: boolean
    }

    export function mkdirSync($path: string, $options: IfOptions_mkdir|number) {
        try {
...

关于我可能/应该如何扩展外部模块的任何想法?

Question

所有3条评论

我认为这可以工作,为可读性赢得分数:

module System.Fs.Node {
    export * from "fs";

    export function mkdirSync($path: string, $options: IfOptions_mkdir|number) {
     //...
    }
  }

你今天可以这样做:

在单独的 .d.ts 文件中:

declare module "fs" {
  stuff: number;
}

在你的猴子补丁中:

/// reference the above .d.ts file
import fs = require('fs');
fs.stuff = 3;

我不认为我们会为此添加额外的语法,因为它(希望?)不是一个常见的场景。

FWIW 在使用节点解析和“适当的外部模块”时不再起作用。 环境模块简单地覆盖任何节点解析的模块。

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

OliverJAsh picture OliverJAsh  ·  242评论

sandersn picture sandersn  ·  265评论

fdecampredon picture fdecampredon  ·  358评论

RyanCavanaugh picture RyanCavanaugh  ·  205评论

blakeembrey picture blakeembrey  ·  171评论