-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
ts: Add missing IDL types #2688
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as anchor from "@coral-xyz/anchor"; | ||
import { Idl } from "@coral-xyz/anchor"; | ||
import { expect } from "chai"; | ||
|
||
import { Generics, IDL } from "../target/types/generics"; | ||
|
||
describe("Generics", () => { | ||
anchor.setProvider(anchor.AnchorProvider.env()); | ||
|
||
/** | ||
* Checks if the IDL produced by Anchor CLI is compatible with the TypeScript | ||
* `Idl` type. Detects a potential mismatch between Rust and TypeScript IDL | ||
* definitions. | ||
*/ | ||
it("Raw IDL", () => { | ||
const idl: Idl = IDL; | ||
expect(idl).to.not.be.undefined; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This wouldn't hurt to merge but the reason why these types were not added was because they are not yet stable, and not supported with the default IDL generation method(
idl-parse
).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.
Well, IDL produced by idl-parse method is still going to satisfy the
Idl
type, so I don't think that keeping unstable types there is going to break anything or be backwards-incompatible. I could add some comments.On the other hand, not having them there makes idl-build not fully usable, as soon as you have any generics in your struct, which I think is a bug.
To be fair - I know that previous versions of Anchor didn't support generics - we are maintaining a fork with ugly patches to make that work in Anchor 0.28. 😢 That, and we also have a hacky way for supporting fields with types from external dependencies and for supporting Accounts structs wrapped by your own macros (we have a macro adding accounts which are mandatory in Light Protocol, so you don't have to copy them over all the time). They are ugly enough that I've never tried to upstream them and I've also seen the idl-build effort going on, so decided to wait. Supporting such use-cases with idl-parse method is horrible. I sincerely hope that one day idl-build is just going to fully replace idl-parse.
I'm looking forward to ditch our fork, because the idl-build method seems to work for us with this patch. Idl-parse solves all the problems that drove us towards patching 0.28 (it works absolutely fine with fields with types from external crates, supports generics and custom macros wrapping Accounts).
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.
This was more to discourage the use of the unimplemented types as those types could change in a backwards-incompatible manner.
Adding these types will only remove the type error which doesn't even exist in the runtime code. With these changes, if you were to use those types in any way, you'll get runtime errors instead of a compile-time error because they are not implemented.
Those patches sound painful and I'm glad
idl-build
is useful for you guys. As for replacing the default generation method, I think the best way forward will be to combine the generation methods in order to get the best of both worlds as there are some parts where it makes more sense to useidl-parse
and some parts withidl-build
. Furthermore, keeping 2 different generation methods is not maintainable as some features can only be implemented in one of the generation methods which results in discrepancy between the generated IDLs.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.
This is fixed in #2824, along with many other things with the IDL. It would greatly help if you could try it out and give feedback before it's included in a release, as it becomes harder to make changes after people start using it.
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.
That's awesome! I will give it a try later today.