haxiomic / dts2hx

Converts TypeScript definition files (d.ts) to haxe externs (.hx) via the TypeScript compiler API
MIT License
135 stars 9 forks source link

support rust's wasm-pack *.d.ts? #121

Closed sonygod closed 2 years ago

sonygod commented 2 years ago

support rust's wasm-pack *.d.ts?

I try to use this cmd

npx dts2hx pkg/index.d.ts --tsconfig .\tsconfig.json

**> Converting module pkg/index

Error: TypeError: Cannot read properties of undefined (reading 'length')**

here is the test file.

/* tslint:disable */
/* eslint-disable */
/**
* @param {Float32Array} v0
* @param {Float32Array} v1
* @param {Float32Array} v2
* @param {Float32Array} u0
* @param {Float32Array} u1
* @param {Float32Array} u2
* @param {number | undefined} epsilon
* @returns {boolean}
*/
export function noDivTriTriIsect(v0: Float32Array, v1: Float32Array, v2: Float32Array, u0: Float32Array, u1: Float32Array, u2: Float32Array, epsilon?: number): boolean;
/**
* @param {Float32Array} m1
* @param {Float32Array} m2
* @param {number | undefined} epsilon
* @returns {boolean}
*/
export function meshMeshIsect(m1: Float32Array, m2: Float32Array, epsilon?: number): boolean;

export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;

export interface InitOutput {
  readonly memory: WebAssembly.Memory;
  readonly noDivTriTriIsect: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number) => number;
  readonly meshMeshIsect: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
  readonly __wbindgen_malloc: (a: number) => number;
}

export type SyncInitInput = BufferSource | WebAssembly.Module;
/**
* Instantiates the given `module`, which can either be bytes or
* a precompiled `WebAssembly.Module`.
*
* @param {SyncInitInput} module
*
* @returns {InitOutput}
*/
export function initSync(module: SyncInitInput): InitOutput;

/**
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
* for everything else, calls `WebAssembly.instantiate` directly.
*
* @param {InitInput | Promise<InitInput>} module_or_path
*
* @returns {Promise<InitOutput>}
*/
export default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
haxiomic commented 2 years ago

Works fine for me but I don’t have your tsconfig.json, could you send that over too?

sonygod commented 2 years ago

actually,this file was generated by WASM-PACK tool and default have no tsconfig.json, this files was copy from other

project.

{
    "compilerOptions": {
        "target": "es2016",
        "module": "commonjs",
        "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
        "strict": true,
        "skipLibCheck": true,
        "baseUrl": ".",
        "noEmit": true,
        "noUnusedParameters": true,
        "strictNullChecks": true
    },
    "include": ["pkg","src"],
    "exclude": ["node_modules"]
}
image
haxiomic commented 2 years ago
Screenshot 2022-10-01 at 10 43 41

Works for me testing on macOS, no errors and the externs look correct

I'll test on windows later in the week

haxiomic commented 2 years ago

Update: I can reproduce the failure on window

haxiomic commented 2 years ago

Should be fixed in 0.19.2, let me know :) b367ece7f9d3bc7971d5629654f8b15328fcad78