You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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 expectsdata: number
in Typescript rather thandata?: number
ordata: 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 theoption
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.The text was updated successfully, but these errors were encountered: