Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extending an external module #1293

Closed
jbondc opened this issue Nov 28, 2014 · 3 comments
Closed

Extending an external module #1293

jbondc opened this issue Nov 28, 2014 · 3 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@jbondc
Copy link
Contributor

jbondc commented Nov 28, 2014

I'm trying to extend an external node module:

// 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 {
...

Any thoughts on how I might/should be extending an external module?

@jbondc
Copy link
Contributor Author

jbondc commented Nov 28, 2014

I think this could work, wins points for readability:

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

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

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Dec 1, 2014
@RyanCavanaugh
Copy link
Member

You can do this today:

In a separate .d.ts file:

declare module "fs" {
  stuff: number;
}

In your monkeypatcher:

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

I don't think we're going to add extra syntax for this since it's (hopefully?) not a common scenario.

@jbrantly
Copy link

FWIW this no longer works when using node resolution and "proper external modules". The ambient module simply overrides any node-resolved one.

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants