reflect.TypeView

Any `type` value: `reflect.Type` itself and every reflection kind view.

Reference version

Signature

interface reflect.TypeView

Any type value: reflect.Type itself and every reflection kind view.

Every reflection API that takes a type takes a TypeView, so a kind view goes wherever a reflect.Type does, and so does a class of your own that implements TypeView: the API calls its as_type(). The shared type operations below are default methods that run on the wrapped type value; reflect.Type declares its own. to_string comes from baml.ToString, which reflect.Type and every kind view implement.

Source:<builtin>/reflect/reflect.bamlbytes 3634–5919

Required instance methods

function

as_type

(self) -> reflect.Type throws never

The type value this view wraps, restoring the unnarrowed type. reflect.Type returns itself.

Default instance methods

function

array

(self) -> reflect.Array throws never

Construct an array type whose element is this type.

function

implemented_by

(self, other: reflect.TypeView) -> bool throws never

Reverse of implements: iface.implemented_by(t) is the same as t.implements(iface). false when this type is not an interface, or when other is not a concrete type.

function

implements

(self, other: reflect.TypeView) -> bool throws never

True iff this type nominally implements the interface other. Any concrete type can: a class, an enum, a primitive, a list, a map, ... other pins the interface's associated types (an omitted one takes its default), and only an implementation with exactly those matches: see reflect.Type.implements. false when other is not an interface, or when this type is not a concrete type.

function

kind

(self) -> reflect.TypeKind throws never

Returns the precise kind view of this type value.

function

meta

(
self,
alias: string | null = …,
description: string | null = …,
docstring: string | null = …,
other: map<string, string> | null = …
) -> reflect.WithMeta<reflect.Type> throws never

Pair this type value with schema metadata without changing its identity.

function

optional

(self) -> reflect.Union throws never

Construct the canonical union of this type and null.

function

to_baml

(self) -> string throws reflect.errors.CompilationError

Render deterministic canonical BAML source for this definition. Non-equivalent declarations with the same display name are rejected.