Browse Source

docs: Improve Javascript Anchor Types reference (#3344)

acheron 11 months ago
parent
commit
a9829429b0
1 changed files with 73 additions and 101 deletions
  1. 73 101
      docs/src/pages/docs/javascript-anchor-types.md

+ 73 - 101
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<T>`
+* ```typescript
+  [1, 2, 3]
+  ```
+---
+* ## Vector
+* `Vec<T>`
+* `Array<T>`
+* ```typescript
+  [1, 2, 3]
   ```
 ---
+* ## Option
+* `Option<T>`
+* `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<T>`
-* ```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<T>`
-* `Array<T>`
-* ```javascript
-  await program
-    .methods
-    .init([1, 2, 3])
-    .rpc();
+  Named variant:
+  ```typescript
+  { two: { val: 99 } }
   ```
-
----
-* `Option<T>`
-* `T | null | undefined`
-* ```javascript
-  // `null` for `None`
-  await program
-    .methods
-    .init(null)
-    .rpc();
-
-  // Non-nullish value for `Option<T>`
-  await program
-    .methods
-    .init(42)
-    .rpc();
+  Unnamed (tuple) variant:
+  ```typescript
+  { three: [12, -34] }
   ```
 {% /table %}