Skip to content

Latest commit

 

History

History
78 lines (65 loc) · 1.04 KB

README.md

File metadata and controls

78 lines (65 loc) · 1.04 KB

JavaScript/TypeScript source code translations

The JavaScript and TypeScript source code uses msgpack-js for the MessagePack encoding.

Constant

JavaScript and TypeScript:

export const Pi = 3.141592;

Enumeration

JavaScript:

export const E = {
    This: 1,
    That: 2,

    enc: Int.enc,
    dec: Int.dec,
};

TypeScript:

export const E = Int;

// decl.d.ts
export declare const enum E {
    This = 1,
    That = 2,
}

Struct

JavaScript:

export const S = {
    enc(buf, v) { ... },
    dec(buf) { ... },
};

TypeScript:

export const S = {
    enc(buf, v) { ... },
    dec(buf) { ... },
};

// decl.d.ts
export declare var S: Type<S>;

export interface S {
    Foo: number;
    Bar: number;
}

Union

JavaScript:

export const U = {
    enc(buf, v) { ... },
    dec(buf) { ... },
};

TypeScript:

export const U = {
    enc(buf, v) { ... },
    dec(buf) { ... },
};

// decl.d.ts
export declare var U: Type<U>;

export type U = number | S;