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

How to export TypeScript Type from koffi.struct ? #197

Open
juthomas opened this issue Sep 23, 2024 · 1 comment
Open

How to export TypeScript Type from koffi.struct ? #197

juthomas opened this issue Sep 23, 2024 · 1 comment

Comments

@juthomas
Copy link

Hello,

First of all, thank you for the great work on Koffi !

Is there a way to export a Type from the koffi.struct constructor ?

const MyStruct = koffi.struct('MyStruct', {
  field1: 'uint8_t',
  field2: 'uint32_t',
});

// Would it be possible to export a TypeScript type for this structure?
// Example:
const myObject: MyStruct.type = { field1: 1, field2: 2}

and get for this example the following generated type

type MyStructType = {
  field1: number;
  field2: number;
};

Thank you for your time and consideration !

@juthomas juthomas changed the title How to export TypeScript Type from koffi.struct How to export TypeScript Type from koffi.struct ? Sep 23, 2024
@Koromix
Copy link
Owner

Koromix commented Sep 25, 2024

I barely know anything about TypeScript.

Maybe you can use koffi.introspect(MyStructType) on the type object returned by koffi.struct() and make some kind of dynamic TypeScript type from that?

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