Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Describe safe types in styleguide #1577

Open
verytactical opened this issue Jan 27, 2025 · 0 comments
Open

Describe safe types in styleguide #1577

verytactical opened this issue Jan 27, 2025 · 0 comments
Labels
scope: dev-docs Internal documentation of the Tact compiler and the repository. (dev-docs/)

Comments

@verytactical
Copy link
Contributor

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
@verytactical verytactical added the scope: dev-docs Internal documentation of the Tact compiler and the repository. (dev-docs/) label Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: dev-docs Internal documentation of the Tact compiler and the repository. (dev-docs/)
Projects
None yet
Development

No branches or pull requests

1 participant