-
Notifications
You must be signed in to change notification settings - Fork 478
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
Adds Typescript definitions. #205
Conversation
index.d.ts
Outdated
interface CompilerOutputContracts { | ||
[globalName: string]: { | ||
[contractName: string]: { | ||
abi: Abi; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these are optional. I'm not sure it is a good idea to have forced description the JSON, it is not actually part of solc-js, but part of Solidity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean abi
and evm
? The rest are already marked as optional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything in the JSON output is optional as it depends on the JSON input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anywhere that this is documented? When you say "everything is optional" I'm pretty sure you don't actually mean everything as (for example) I don't believe that you can configure the output to omit type
in the AbiFunction
structure. Perhaps you just mean "each of the top level keys under [contractName: string]
are optional"? Are all of them actually optional or are some of them optional in the sense that they may be empty objects or empty arrays? Looking at the docs, the example shows several as having empty arrays or empty objects and I vaguely remember when I was working with these a while back encountering some situations where rather than being omitted an empty object or array was included (but I could be misremembering).
My goal here is to accurately represent the structure of the object returned by the Solidity compiler. My inquiries are because I really have no idea exactly what it can spit out, so I need some help specifying it.
If you really want to go above and beyond to help out, a comment on each non-optional thing that can be optional would be ideal. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking over the docs again, I have added a few more optional indicators (locally). However, it is unclear from the docs whether evm.bytecode
will be included if all of the members of evm.bytecode
are excluded? Or perhaps it will just be an empty object in this case? Similar question for ewasm
section, is it an empty object if ewasm.wast
and ewasm.wasm
are filtered out or is it omitted entirely if they are filtered out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question for the top level things, will the contracts
key be omitted entirely if everything is filtered out from it, or will it always be present with an empty object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of it is documented here: http://solidity.readthedocs.io/en/develop/using-the-compiler.html#compiler-input-and-output-json-description
The ABI is documented here (but that is again outside the scope of the JSON compiler interface, it is a specification shared between languages and clients): http://solidity.readthedocs.io/en/develop/abi-spec.html#json
I think the JSON compiler interface documentation needs to be refined way more than it is currently, but the assumption is everything can be filtered out, based on the input selection. The truth current may be different, specific to the actual implementation, but we should just specify it properly in the documentation and follow that on the consumer side.
As a user, I depend on solcjs, not Solidity (I get that transitively). Therefore, I should be able to get the typescript definitions through solcjs. Specifically, I call functions in the I don't believe there is any easy way to bundle TypeScript definitions with Solidity such that I can get them transitively via solcjs, which is why I have added them here. I'm certainly open to other mechanisms for making the definition files available, but this seemed like the best option from a usability standpoint. |
The two links you provided (@axic) in your comment how I created this file in the first place. If you believe I have mis-interpreted the documentation or there is otherwise an error in this definition I encourage you to point it out (please be specific). I have updated the PR with a couple changes for where I believe I had a mistake previously (non-optional fields), but the documentation is not particularly clear on what happens when a node in the object graph would be an empty array or empty object; will the node be omitted or will it be empty? |
Examples of what is unclear are the top three keys (errors, sources, contracts) and |
Any progress on this? Would love to have TypeScript defs. |
It seems like this is ready to go... any updates? Thanks in advance! |
@MicahZoltu @danqing @cruhl sorry for the delays, we just need to understand Typescript better since otherwise we cannot maintain it and merging means we have to maintain it. Would it be possible to add tests which use the typescript definition? |
index.d.ts
Outdated
userdoc?: any; | ||
devdoc?: any; | ||
ir?: string; | ||
evm: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even evm
is optional, not only the fields below. Practically everything is optional in the response JSON.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note: I'm not a fan of responses where everything is optional, it makes the receiver have to litter their code with null coalescing which is painful in JavaScript. However, that is out of scope of this PR which is just trying to match reality.
There isn't really a way to "test" definition files unless you author your actual tests in TypeScript (which I generally recommend, but is out of scope for this PR). It is a matter of whether the definition files line up with reality, and testing that means writing a test that tests actual functionality in TypeScript. If there is a mismatch, either the test will fail to compile or the test will fail. |
Is this definition also relevant for the user with I'm trying to match the definitions with the actual use or the code in the console.log(contractName + ': ' + output.contracts[contractName].bytecode) But Lines 112 to 148 in bab0fef
|
Last I checked |
Looking at the Readme of the repository and the definitions I would assume it will not work. Also it did not work for me in a local project with this specific example. As far as I know, the Typescript people write tests which work with their definitions and run the Typescript compiler on them. Could be an option. |
At the point in time when I submitted this PR it worked. The definition file that project uses can be found here: https://github.com/AugurProject/augur-core/blob/master/typings/solc/index.d.ts Uses solc 0.4.20 |
Is this still being worked on? Would love to have TypeScript definitions for solc-js! |
I'm not actively working on it, but would still like to get it merged. I'm unclear if there is anything realistic that we could do to get this merged. To maintainers: Can you decide yay or nay on this rather than limbo? If you decide nay it can be added to DefinitelyTyped so people can still benefit (though not as cleanly). |
Any update on this PR? |
The API with 0.5.0 changed significantly. It only supports strings externally and as a result there's no need to define the JSON (including ABI JSON). @MicahZoltu can you update the PR? I'd like to merge it after. |
To clarify: if you could create a PR which only adds types to the public methods on wrapper (e.g. without the standard JSON/ABI) that could be merged quickly. The rest of this PR is more complicated. |
Hmm, I haven't followed Solidity 5.0, and I don't understand what you mean by "it only supports strings externally". |
The only important entry point is |
This isn't complete, but it is _way_ better than nothing and gives a place for people to add additional typescript definitions in the future. Recommend switching over to TypeScript for this library so this file is generated automatically. :)
I have created ea new PR that only contains the While I'm happy to see that PR get merged as it is a good starting point for getting TypeScript definitions included, I don't feel that it is nearly as useful as getting the JSON input/output well defined. I'm also curious why the |
Hi, thank you very much for this PR. However, part of what was discussed here was already implemented or is under development in other PRs (e.g. #630), so I will be closing this for now. Please, feel free to reopen it if necessary. |
This isn't complete, but it is way better than nothing and gives a place for people to add additional typescript definitions in the future. Recommend switching over to TypeScript for this library so this file is generated automatically. :)