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
Write a section that describes which types are safe to use, so that
we can automatically generate schemas
development is not hindered by having to redefine them
TLDR:
Prefer type over interface where you most likely want to see fields in hover tooltip (usually for initially encoded data, for example AST)
Prefer interface over type when end user doesn't have to know what's inside (usually when fields have functions as their types)
Allowed
disjoint object unions with readonly fields, union and all branches must have a name, only 1 field is a tag and it's always named kind and is always string literal, union defined before the branches
ok: true is a bad tag
type A = { a: A } | { b: B } is a bad union: no tag, to names to branches
literal unions, always must have a name
type A = { x: 'a' | 'b' } has an unnamed literal union
literal types
string, number, boolean
T | undefined if T is guaranteed to never be undefined
tuples of small size
objects with readonly fields, always must have a name
Set and Map
Record, but it's discouraged
arrays, but they must be a Set or Map if things have unique tag (avoid .find())
generics, but without extends
functions, but very discouraged as they don't serialize
Disallowed
optional fields foo?: number as they are number + 1 + 1 algebraically, buggy, and also very hard to support in schema
extending union with union type A = B | C; type D = A | E
imported types import { Cell } from "@ton/core", there is no way to generate schema for them
The text was updated successfully, but these errors were encountered:
Write a section that describes which types are safe to use, so that
TLDR:
type
overinterface
where you most likely want to see fields in hover tooltip (usually for initially encoded data, for example AST)interface
overtype
when end user doesn't have to know what's inside (usually when fields have functions as their types)Allowed
kind
and is always string literal, union defined before the branchesok: true
is a bad tagtype A = { a: A } | { b: B }
is a bad union: no tag, to names to branchestype A = { x: 'a' | 'b' }
has an unnamed literal unionstring
,number
,boolean
T | undefined
ifT
is guaranteed to never be undefinedSet
andMap
Record
, but it's discouragedSet
orMap
if things have unique tag (avoid.find()
)extends
Disallowed
foo?: number
as they arenumber + 1 + 1
algebraically, buggy, and also very hard to support in schematype A = B | C; type D = A | E
import { Cell } from "@ton/core"
, there is no way to generate schema for themThe text was updated successfully, but these errors were encountered: