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 types #19

Closed
jacque006 opened this issue Jun 11, 2021 · 5 comments
Closed

Typescript types #19

jacque006 opened this issue Jun 11, 2021 · 5 comments

Comments

@jacque006
Copy link

Would be nice to have Typescript typing for this library, either in this repo or via DefinetlyTyped (@types/mcl-wasm).

@herumi
Copy link
Owner

herumi commented Jun 13, 2021

Okay, I'll make it. Please wait a moment.

@herumi
Copy link
Owner

herumi commented Jun 21, 2021

I'm developing https://github.com/herumi/mcl-wasm/blob/typescript/src/index.d.ts and it seems to run mostly well.
But it has something wrong.
If I comment out mapToG1,

% npx tsc test/test-ts.ts
test/test-ts.ts:247:13 - error TS2345: Argument of type 'Fr' is not assignable to parameter of type 'Fp'.
  Property 'mapToG1' is missing in type 'IntType' but required in type 'Fp'.

247     z.set_a(c)
                ~

  src/index.d.ts:49:5
    49     mapToG1(): G1; // QQQ : why does this cause an error?
           ~~~~~~~
    'mapToG1' is declared here.

test/test-ts.ts:447:25 - error TS2345: Argument of type 'Fr' is not assignable to parameter of type 'G1'.
  Type 'IntType' is missing the following properties from type 'G1': setX, setY, setZ, getX, and 5 more.

447   const e = mcl.pairing(mcl.mul(mpk, r), Q)

I I wonder why mcl.add for Fp returns mcl.Fr.
I'm just starting to study TypeScript and I'm not sure.

@herumi
Copy link
Owner

herumi commented Jun 21, 2021

I've solved it by adding a never member to distinguish Fp and Fr.

@herumi
Copy link
Owner

herumi commented Jun 21, 2021

6c4d1c0

@herumi herumi closed this as completed Jun 30, 2021
@jacque006
Copy link
Author

Thanks @herumi !

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