diff --git a/docs/src/pages/docs/javascript-anchor-types.md b/docs/src/pages/docs/javascript-anchor-types.md index ce3e632062..2d9cfaef62 100644 --- a/docs/src/pages/docs/javascript-anchor-types.md +++ b/docs/src/pages/docs/javascript-anchor-types.md @@ -8,132 +8,104 @@ This reference shows you how Anchor maps Rust types to JavaScript/TypeScript typ --- {% table %} -* Rust Type -* JavaScript Type +* Type +* Rust +* TypeScript * Example -* Note --- +* ## Boolean * `bool` * `boolean` -* ```javascript - await program - .methods - .init(true) - .rpc(); +* ```typescript + true ``` --- -* `u64/u128/i64/i128` -* `anchor.BN` -* ```javascript - await program - .methods - .init(new anchor.BN(99)) - .rpc(); - ``` -* [https://github.com/indutny/bn.js](https://github.com/indutny/bn.js ) ---- +* ## Integer * `u8/u16/u32/i8/i16/i32` * `number` -* ```javascript - await program - .methods - .init(99) - .rpc(); - ``` +* ```typescript + 99 + ``` +--- +* ## Big integer +* `u64/u128/i64/i128` +* `anchor.BN` +* ```typescript + new anchor.BN(99) + ``` --- +* ## Float * `f32/f64` * `number` -* ```javascript - await program - .methods - .init(1.0) - .rpc(); - ``` +* ```typescript + 1.0 + ``` --- -* `Enum` -* `object` -* ```rust - enum MyEnum { - One, - Two { val: u32 }, - Three(u8, i16), - }; +* ## String +* `String` +* `string` +* ```typescript + "hello" ``` - ```javascript - // Unit variant - await program - .methods - .init({ one: {} }) - .rpc(); - - // Named variant - await program - .methods - .init({ two: { val: 99 } }) - .rpc(); - - // Unnamed (tuple) variant - await program - .methods - .init({ three: [12, -34] }) - .rpc(); +--- +* ## Array +* `[T; N]` +* `Array` +* ```typescript + [1, 2, 3] + ``` +--- +* ## Vector +* `Vec` +* `Array` +* ```typescript + [1, 2, 3] ``` --- +* ## Option +* `Option` +* `T | null | undefined` +* `None`: + ```typescript + null + ``` + `Some(val)`: + ```typescript + 42 + ``` +--- +* ## Struct * `Struct` -* `{ val: {} }` +* `object` * ```rust struct MyStruct { val: u16, } ``` - ```javascript - await program - .methods - .init({ val: 99 }) - .rpc(); + ```typescript + { val: 99 } ``` --- -* `[T; N]` -* `Array` -* ```javascript - await program - .methods - .init([1, 2, 3]) - .rpc(); +* ## Enum +* `Enum` +* `object` +* ```rust + enum MyEnum { + One, + Two { val: u32 }, + Three(u8, i16), + } ``` ---- -* `String` -* `string` -* ```javascript - await program - .methods - .init("hello") - .rpc(); + Unit variant: + ```typescript + { one : {} } ``` ---- -* `Vec` -* `Array` -* ```javascript - await program - .methods - .init([1, 2, 3]) - .rpc(); + Named variant: + ```typescript + { two: { val: 99 } } ``` - ---- -* `Option` -* `T | null | undefined` -* ```javascript - // `null` for `None` - await program - .methods - .init(null) - .rpc(); - - // Non-nullish value for `Option` - await program - .methods - .init(42) - .rpc(); + Unnamed (tuple) variant: + ```typescript + { three: [12, -34] } ``` {% /table %}