KScript docs
EN

type fields and methods

A <type> declared by a script, such as Repo.

A field is a plain fact about the value, read with a dot and no brackets: $value.name. A method takes arguments or does work, and is called with ->: $value->name(arguments), or with the value piped in: $value |> name(arguments).

Fields

FieldTypeDescription
.descriptionstringWhat the type is for, or null.
.fieldslistThe type's fields: name, type, optional, from, computed and description.
.namestringThe type's name.

From KScript.Core

#type->check(data) → list

The problems that stop the data fitting this type, as { path, field, message } maps. Empty when it fits.
Example
<type name="User" fields="login: string, id: int" />
<echo>{ User->check({ login: 'joan', id: 'seven' })->map(fn(p) => $p.message) }</echo>
type User {
  login: string
  id: int
}
echo User->check({ login: 'joan', id: 'seven' })->map(fn(p) => $p.message)

#type->is(value) → bool

True when the value is a record of this type, or of a type built on it with with [...]. Given a type, true when that type is this one or is built on it.
Example
<type name="User" fields="login: string" />
<type name="Admin" with="User" fields="level: int" />
<let name="joan" value="Admin({ login: 'joan', level: 2 })" />
<echo>{ User->is($joan) } { User->is(Admin) } { Admin->is(User) }</echo>
type User {
  login: string
}
type Admin with [User] {
  level: int
}
$joan = Admin({ login: 'joan', level: 2 })
echo "{ User->is($joan) } { User->is(Admin) } { Admin->is(User) }"

#type->schema() → map

The type as a JSON Schema map.
Example
<type name="User" fields="login: string, id?: int" />
<echo>{ User->schema() }</echo>
type User {
  login: string
  id?: int
}
echo User->schema()

Methods from any