pub struct ObjectField {
pub ty: Type,
pub optional: bool,
pub readonly: bool,
pub method: bool,
}Expand description
optional: true means reads widen to ty | undefined and construction may omit the field.
Distinct from a value-nullable field (ty: T | null, optional: false): must be present
but can be null.
Fields§
§ty: Type§optional: bool§readonly: boolreadonly forbids writes through the field; assignability treats a writable
target field invariantly (see assignable.rs). Inferred object literals and
freshly-synthesized shapes are writable (false); only an explicit readonly
modifier on an object-type/interface property sets this.
method: boolA method rather than a function-typed property. tsc compares a method’s
parameters bivariantly and a property’s contravariantly.
Implementations§
Source§impl ObjectField
impl ObjectField
pub fn required(ty: Type) -> Self
pub fn optional(ty: Type) -> Self
Sourcepub fn read_ty(&self) -> Type
pub fn read_ty(&self) -> Type
The type a read of this field yields: an optional field widens to
T | undefined, since an absent property reads as undefined. Every field
read — object type, interface property, class field, union member, and
codegen’s mirror of all four — goes through this, so the widening rule
has one definition.
Trait Implementations§
Source§impl Clone for ObjectField
impl Clone for ObjectField
Source§impl Debug for ObjectField
impl Debug for ObjectField
Source§impl<'de> Deserialize<'de> for ObjectField
impl<'de> Deserialize<'de> for ObjectField
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for ObjectField
Source§impl Ord for ObjectField
impl Ord for ObjectField
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for ObjectField
impl PartialEq for ObjectField
Source§impl PartialOrd for ObjectField
impl PartialOrd for ObjectField
Source§impl Serialize for ObjectField
impl Serialize for ObjectField
impl StructuralPartialEq for ObjectField
Auto Trait Implementations§
impl Freeze for ObjectField
impl RefUnwindSafe for ObjectField
impl Send for ObjectField
impl Sync for ObjectField
impl Unpin for ObjectField
impl UnsafeUnpin for ObjectField
impl UnwindSafe for ObjectField
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,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.