pub enum TsType {
Named {
name: String,
type_args: Vec<TsType>,
},
Array {
element: Box<TsType>,
readonly: bool,
},
Object(Vec<TsTypeMember>),
Fn {
params: Vec<TsType>,
ret: Box<TsType>,
},
Union {
members: Vec<TsType>,
multiline: bool,
},
Intersection(Vec<TsType>),
}Expand description
A type-position node. Named (extended with type arguments — a real gap
the reference sketch left unaddressed: Record<string, Array<{...}>>/Promise<Response> both need one, and a bare Named
with no type-argument slot cannot represent either), Array (extended
with a readonly modifier — P7.9’s own real gap: every List/Query
element type bynk-emit’s ts_type_ref*/ts_ty families build is
readonly T[], not plain T[]), Object, and Fn (P7.9’s own second
real gap — the query-thunk wrapper (() => readonly T[]) and a real
parametered function type (a0: T0, …) => Ret both need one) — not the
sketch’s Union/Intersection/Literal/TypeParam/Readonly (still
unused; readonly here is a modifier on Array, not the sketch’s own
separate Readonly wrapper variant).
Variants§
Named
A named type, optionally generic — string/unknown (no type
arguments) or Record<string, T>/Promise<Response> (some).
Array
T[] (readonly: false) or readonly T[] (readonly: true) —
TypeScript’s own postfix array-type syntax (not the equivalent
Array<T>/ReadonlyArray<T> generic spelling either family uses).
Hazard (review of #1315/#1316, not yet closed): the printer does
not parenthesise element when it is itself a TsType::Union or
TsType::Fn — Array { element: Union(..), .. } prints as
A | B[], which TypeScript reads as A | (B[]), not the intended
(A | B)[]; likewise a Fn element’s own [] binds to its return
type, not the whole function type. Not a P7.9 regression — every
bynk-emit call site building this exact malformed shape
(Ty::List of an Ty::ActorSum) produced the identical bytes
before this slice too, so the zero-diff bar is genuinely met. Fixing
it is a real output change, out of this slice’s own behaviour-
preserving scope — a caller building Array over Union/Fn today
must not trust the printer to parenthesise correctly.
Object(Vec<TsTypeMember>)
A type-position object shape, e.g. { type: string; payload: unknown }
— semicolon-separated, always printed on one line (see
TsExpr::Object’s own doc for the value-position contrast). An
interface’s own members are each printed on their own line by
TsDecl::Interface’s printer, independent of this variant’s own
(always-inline) rendering — the two only look different because
TsDecl::Interface is the thing choosing to put each member on its
own line, not because Object has two rendering modes.
#1323 replaced the plain Vec<(String, TsType, bool)> (optional
only, #1321) with TsTypeMember — workers_entry.rs’s own real
gap needed both a readonly modifier (every structural type this
file builds is readonly-qualified, e.g. { readonly cron: string; readonly scheduledTime: number }) and a method-signature member
(ack(): void, retry(): void, waitUntil(promise: Promise< unknown>): void), neither representable by one more anonymous
tuple bool — a fourth positional bool next to optional would
be genuinely ambiguous at call sites (readonly vs. optional, ordered
how?), the same reasoning TsObjectEntry already used over a raw
tuple for the value-position sibling.
Fn
(a0: T0, a1: T1, …) => Ret — a function type. Parameters carry no
name of their own (just their type); the printer numbers them
positionally (a0, a1, …), matching the exact convention
bynk-emit’s own pre-P7.9 ts_type_ref_with/ts_ty already used
(TypeScript requires some name in function-type syntax, and
nothing about a TypeRef::Fn/Ty::Fn parameter carries a real one
to use instead). A zero-params Fn is the query-thunk wrapper
shape, () => Ret. See TsType::Array’s own doc for a real,
unclosed parenthesisation hazard when a Fn sits inside one.
Union
A | B | C — a type-position union. Added in review of #1315:
bynk-emit’s ts_ty builds a real union type for a resolved
multi-actor sum (Ty::ActorSum, discriminated-union members tagged
by actor name), a shape none of Named/Array/Object/Fn can
represent — a real, grounded gap the same way readonly/Fn
themselves were (P7.9’s own accepted proposal), not a speculative
addition. Each member prints through the ordinary render_type
recursion; a member that is itself a Union is legal to construct
but nothing in bynk-emit builds one today. See TsType::Array’s
own doc for a real, unclosed parenthesisation hazard when a Union
sits inside one.
multiline (#1339): false (via TsType::union) is this variant’s
original single-line A | B | C form, unchanged. true (via
TsType::multiline_union) is emit_sum_type’s own real
discriminated-union shape — one variant per line, a leading | on
every line except the first (which gets equivalent spacing
instead), the closing ; appended directly to the last variant’s own
line. Mirrors TsExpr::Object’s own multiline field precedent
(#1317), but — unlike that one — needs no depth-aware wrapper: the
pre-conversion writeln! code this reproduces always used a fixed
two-space indent regardless of nesting (this shape is only ever a
top-level export type alias body, never nested inside another
type), so render_type stays entirely depth-unaware here too. Only
rendered correctly from TsDecl::TypeAlias’s own top-level
render — not reachable, and not given a defined rendering, from any
nested position (an array element, a type argument, …), the same
named boundary TsExpr::Object’s own multiline doc already
draws for its own nested case.
Intersection(Vec<TsType>)
A & B — a type-position intersection. #1339’s own real gap:
emit_refined_type’s own branded-type alias,
{base} & { readonly __brand: "..." }, has no representation among
Named/Array/Object/Fn/Union — mirrors Union’s own
shape/precedent exactly (a flat Vec, each member printed through
the ordinary render_type recursion, joined by &), single-line
only (nothing in bynk-emit builds a multi-line intersection).
Implementations§
Source§impl TsType
impl TsType
Sourcepub fn named(name: impl Into<String>) -> Self
pub fn named(name: impl Into<String>) -> Self
A plain named type with no type arguments — string, unknown,
Request, …
Sourcepub fn named_with_args(name: impl Into<String>, type_args: Vec<TsType>) -> Self
pub fn named_with_args(name: impl Into<String>, type_args: Vec<TsType>) -> Self
A generic named type — Record<K, V>, Promise<T>, …
Sourcepub fn readonly_array(element: TsType) -> Self
pub fn readonly_array(element: TsType) -> Self
readonly T[].
Sourcepub fn union(members: Vec<TsType>) -> Self
pub fn union(members: Vec<TsType>) -> Self
A | B | C — the original single-line union form, unchanged.
Sourcepub fn multiline_union(members: Vec<TsType>) -> Self
pub fn multiline_union(members: Vec<TsType>) -> Self
emit_sum_type’s own real multi-line discriminated-union shape — see
TsType::Union’s own doc for the exact rendering rules and why
this needs no depth parameter.
Sourcepub fn intersection(members: Vec<TsType>) -> Self
pub fn intersection(members: Vec<TsType>) -> Self
A & B — an intersection type.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TsType
impl RefUnwindSafe for TsType
impl Send for TsType
impl Sync for TsType
impl Unpin for TsType
impl UnsafeUnpin for TsType
impl UnwindSafe for TsType
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);