Types
Note: The TypeScript type expression is derived from
Anchor::TypeScript::Serializer
for TypeScript schema generation.
Legend
T
can be any of the types defined in the table +Anchor::Types::Relationship
(e.g.Anchor::Types::String
)- in the type expression column it's the serialized version (e.g.
string
)
- in the type expression column it's the serialized version (e.g.
Ts
:T[]
props
:Array<Anchor::Types::Property>
Anchor::Types | TypeScript type expression |
---|---|
String | string |
Integer | number |
Float | number |
BigDecimal | string |
Boolean | boolean |
Null | null |
Unknown | unknown |
Maybe.new(T) | Maybe<T> |
Array.new(T) | Array<T> |
Record | Record<string, unknown> |
Record.new(T) | Record<string, T> |
Reference.new(name) | name (directly used as type identifier) |
Literal.new(value) | "#{value}" if string , else value.to_s |
Enum | Enum.anchor_schema_name (directly used as type identifier) |
Union.new(Ts) | Ts[0] | Ts[1] | ... |
Object.new(props) | { [props[0].name]: props[0].type, [props[1].name]: props[1].type, ... } |
Anchor::Types::Relationship
Anchor::Types::Object
.property(name, type, optional: nil, description: nil)
name
:String
type
: member ofAnchor::Types
optional
:Boolean
- whether the property is optional, e.g. if
true
,{ name?: string }
- as opposed to asserting
Anchor::Types::Maybe.new(Anchor::Types::String)
to get{ name: Maybe<string> }
serialized
- as opposed to asserting
- whether the property is optional, e.g. if
description
:String
- serialized as a comment in TypeScript
Anchor::Types::Enum
Alternatively, you can define it dynamically
Very similar to rmosolgo/graphql-ruby enums.