Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.

Add typescript definitions for ethjs-util methods #248

Merged
merged 3 commits into from
Jun 23, 2020

Conversation

cgewecke
Copy link
Contributor

Attempt to resolve #219 by defining types for ethjs-util locally. Not certain this is the right approach, perhaps it should be done by publishing an @types module.

We should also probably extend the tests to validate the types themselves.

For reference, the ethjs-utils methods are defined here.

@github-actions
Copy link

Coverage Status

Coverage decreased (-0.001%) to 99.673% when pulling 7bb802f on ejs-util-typescript into 3141eda on master.

@cgewecke
Copy link
Contributor Author

@holgerd77

This is still draft...do you have any advice about what direction this should go in, if any.. 🙂

src/index.ts Outdated Show resolved Hide resolved
@holgerd77
Copy link
Member

I will leave this to @s1na to make a comment here since he started the issue. From my side this looks like a good start.

@holgerd77
Copy link
Member

I've now excluded this from the v7.0.0 release #249. Then we can go here on a bit more relaxed pace and this can very well also be added within a subsequent patch release together with other changes.

@s1na
Copy link
Contributor

s1na commented Apr 30, 2020

Hm also not sure what's the best approach. I guess having the typedefs locally is okay since their repo hasn't changed much in the last 2 years. Ideally they'd merge these typedefs upstream and do a release. Or having these as under a types package as you suggested.

We could also consider "forking" their code (if licenses are compatible) locally into the repo.

tsconfig.json Outdated
@@ -1,4 +1,4 @@
{
"extends": "@ethereumjs/config-tsc",
"include": ["src/**/*.ts", "test/**/*.ts"]
"include": ["src/**/*.ts", "test/**/*.ts", "typings/**/*.js"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is typo.

- "typings/**/*.js"
+ "typings/**/*.ts"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest that the another approach.

compileOptions.typeRoots's default value is @types.
So make below folders and put ethjs-util.d.ts to index.d.ts.
You don't need to modify tsconfig.json

- src
    - @types
        - ethjs-util
            - index.d.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomonari Thanks so much for catching this! Makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomonari Unfortunately, fixing the typo does not seem to resolve the requirement that ethjs-util be imported at the top of index.ts with a path reference comment.

Also had no luck with your suggestion about adding @types folder in src. Maybe something strange is going on with extending the ethereumjs config, idk.

Copy link
Contributor

@tomonari-t tomonari-t Jun 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cgewecke
Thanks for trying it.
I also tried and find out that it is not caused of ts but karma-typescript.
I'm dealing with it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cgewecke
I made example code. Please check tomonari-t#2.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomonari-t

Yes that works! Have made your suggested changes in 40ecfe9 and added you as the commit author. Thank you for investigating this.

@tomonari-t
Copy link
Contributor

tomonari-t commented Jun 3, 2020

@s1na
Your typedef is awesome!
I think it is best that creating PRs the adding typedef of ethjs-util to @types repository.

@lgtm-com
Copy link

lgtm-com bot commented Jun 3, 2020

This pull request introduces 1 alert when merging c5ee67f into 58c2476 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@cgewecke cgewecke marked this pull request as ready for review June 4, 2020 15:43
Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks Chris

@holgerd77 holgerd77 merged commit d485939 into master Jun 23, 2020
@holgerd77 holgerd77 deleted the ejs-util-typescript branch June 23, 2020 09:32
@holgerd77
Copy link
Member

@cgewecke @tomonari-t just discovered on some experimentation around #257 that the changes on the tsconfig.json and tsconfig.prod.json files here broke the distribution build since source files are now placed in dist/src instead of dist, also the types from this PR are not transfered to the dist folder on build.

Can you have a look here and open a PR fixing this?

@cgewecke
Copy link
Contributor Author

cgewecke commented Jul 2, 2020

@holgerd77 Sorry about this. Have opened #260 which I think fixes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Types not detected for ethjs-util re-exported methods
4 participants