Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Idea: generate the TypeScript .d.ts definition files #8

@remorses

Description

@remorses

Napigen already has all the Zig function and struct signatures which means it should be easy to add .d.ts files generation

This would make the generated .node module type safe

For example this code

const std = @import("std");
const napigen = @import("napigen");

export fn add(a: i32, b: i32) i32 {
    return a + b;
}

comptime {
    napigen.defineModule(initModule);
}

fn initModule(js: *napigen.JsContext, exports: napigen.napi_value) !napigen.napi_value {
    try js.setNamedProperty(exports, "add", try js.createFunction(add));

    return exports;
}

Would generate the following declartation:

export function add(a: number, b: number): number

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions