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

Typescript declarations #31

Open
hetsch opened this issue Dec 6, 2017 · 2 comments
Open

Typescript declarations #31

hetsch opened this issue Dec 6, 2017 · 2 comments

Comments

@hetsch
Copy link

hetsch commented Dec 6, 2017

Hi,
currently I'm using your package in a Typescript project that I have inherited from a collegue. I really enjoy working with it, so far. What do you think about generating some Typescript declaration files?

I've never done it by hand so far, but Microsoft provides a generator that might be helpful dts-gen (https://github.com/Microsoft/dts-gen).

Calling dts-gen -m struct is not very helpful:

/** Declaration file generated by dts-gen */

export = struct;

declare function struct(...args: any[]): any;

declare namespace struct {
    // Circular reference from struct
    const Struct: any;

    const prototype: {
    };

}
@hetsch
Copy link
Author

hetsch commented Dec 7, 2017

This might work:

/// <reference types="node" />

declare module 'struct' {
  import { Buffer } from "buffer";

  export class Struct {
    word8(name: string): void;
    word8Sle(name: string): void;
    word8Sbe(name: string): void;
    word16Sle(name: string): void;
    word16Sbe(name: string): void;
    word16Ule(name: string): void;
    word16Ube(name: string): void;
    word32Sle(name: string): void;
    word32Sbe(name: string): void;
    word32Ule(name: string): void;
    word32Ube(name: string): void;
    word64Sle(name: string): void;
    word64Sbe(name: string): void;
    word64Ule(name: string): void;
    word64Ube(name: string): void;
    floatle(name: string): void;
    floatbe(name: string): void;
    doublele(name: string): void;
    doublebe(name: string): void;
    chars(name: string, length: number, encoding?: string): void;
    charsnt(name: string, length: number, encoding?: string): void;
    array(name: string, length: number, type?: string | Struct): void;
    struct(name: string, struct: Struct): void;
    get(fieldName: string): any;
    set(fieldName: string, value: any): void;
    allocate(): void;
    _setBuff(buffer: Buffer): void;
    buffer(): Buffer;
    fields: object;
  }
}

@benallfree
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants