Skip to content

Instantly share code, notes, and snippets.

@fearthecowboy
Created August 28, 2015 16:55
Show Gist options
  • Save fearthecowboy/b0cc082d824b8a7a97f9 to your computer and use it in GitHub Desktop.
Save fearthecowboy/b0cc082d824b8a7a97f9 to your computer and use it in GitHub Desktop.
Internal module confusion...
/// <reference path="../node/node.d.ts" />
// bug: shouldn't I be able to reference stream.Writable?
// adding the import line here makes it so that the consumer can't see this class.
// import * as stream from "stream"
declare class BufferedMessagePackEncoder {
private tail;
private encoder;
private stream;
private buffer;
private itemcount;
private onComplete;
// bug: and use 'stream.Writable' instead of 'any' for the stream parameters.
constructor(stream: any, onComplete: (count: number) => void);
// ie - I'd like to do this:
// constructor(stream: stream.Writable, onComplete: (count: number) => void);
write(chunk: any): void;
flush(): void;
}
/// <reference path="../typings/node/node.d.ts" />
/// <reference path="../typings/fluentd/BufferedMessagePackEncoder.d.ts" />
class consumer {
// if the BufferedMessagePackEncoder.d.ts file has the import statement in it
// this file won't be able to reference the class.
private bufferedEncoder: BufferedMessagePackEncoder;
}
@sophiajt
Copy link

Imports/exports turn files into modules. Once it's a module you'll have to load it to use it.

So, if you add the import to BufferedMessagePackEncoder.d.ts, then that file will become a module. After that, you'll need to add an export to line 7, then import that file instead of ing to it. Once imported, you should be able to dot into the module and get to BufferedMesssagePackEncoder. Something like:

/// <reference path="../node/node.d.ts" />

// bug: shouldn't I be able to reference stream.Writable?
// adding the import line here makes it so that the consumer can't see this class.
import * as stream from "stream"

export declare class BufferedMessagePackEncoder {
    private tail;
    private encoder;
    private stream;
    private buffer;
    private itemcount;
    private onComplete;

    // bug: and use 'stream.Writable' instead of 'any' for the stream parameters.
    constructor(stream: any, onComplete: (count: number) => void);

    // ie - I'd like to do this:
    // constructor(stream: stream.Writable, onComplete: (count: number) => void);

    write(chunk: any): void;
    flush(): void;
}


/// <reference path="../typings/node/node.d.ts" />
import * as BMPE from "../typings/fluentd/BufferedMessagePackEncoder.d.ts"

class consumer  {
    // if the BufferedMessagePackEncoder.d.ts file has the import statement in it
    // this file won't be able to reference the class.
    private bufferedEncoder: BMPE.BufferedMessagePackEncoder;
} 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment