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

Allow nullable type for Option fields #1427

Closed
danmt opened this issue Feb 10, 2022 · 0 comments · Fixed by #1428
Closed

Allow nullable type for Option fields #1427

danmt opened this issue Feb 10, 2022 · 0 comments · Fixed by #1428

Comments

@danmt
Copy link
Contributor

danmt commented Feb 10, 2022

Nullable Type for Option Fields

Anchor enables builders to define Optional fields for instruction arguments by using Option in Rust, this works fine, but when using the client in Typescript, the type for the "optional fields" doesn't accept a "nullable" type. i.e. data: Option<u8> in Rust expects data: number in Typescript rather than data?: number or data: number | null.

Expected Behavior

Anchor Typescript client should allow Nullable types for Optional fields.

Solution

The DecodeType from ts/src/program/namespace/type.ts is using conditional types but the option condition defaults to the "option type". If there was a type union for this "option type" with null or undefined, it would work as expected.

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

Successfully merging a pull request may close this issue.

1 participant