Skip to main content

TsValue

Enum TsValue 

Source
pub enum TsValue {
Show 37 variants Undefined, Null, Boolean(bool), Number(f64), String(String), Object(HashMap<String, TsValue>), Array(Vec<TsValue>), Function(Rc<dyn Fn(&[TsValue]) -> TsValue>), Error(String), Union(Vec<TsValue>), Generic(String, Vec<TsValue>), Symbol(String), BigInt(i128), Date(i64), RegExp(String), Map(Vec<(TsValue, TsValue)>), Set(Vec<TsValue>), Promise(Box<TsValue>), Iterable(Box<dyn Iterator<Item = TsValue>>), Conditional(Conditional), Mapped(Mapped), TemplateLiteral(TemplateLiteral), KeyOf(Box<TsValue>), TypeOf(Box<TsValue>), IndexedAccess { object_type: Box<TsValue>, index_type: Box<TsValue>, }, Tuple(Vec<TsValue>), Readonly(Box<TsValue>), Nullable(Box<TsValue>), NonNullable(Box<TsValue>), Infer { type_param: String, constraint: Option<Box<TsValue>>, }, FunctionType { params: Vec<(String, TsValue)>, return_type: Box<TsValue>, }, ConstructorType { params: Vec<(String, TsValue)>, return_type: Box<TsValue>, }, ThisType, Never, Unknown, Any, Void,
}
Expand description

TypeScript 值类型枚举

Variants§

§

Undefined

未定义

§

Null

空值

§

Boolean(bool)

布尔值

§

Number(f64)

数字

§

String(String)

字符串

§

Object(HashMap<String, TsValue>)

对象

§

Array(Vec<TsValue>)

数组

§

Function(Rc<dyn Fn(&[TsValue]) -> TsValue>)

函数

§

Error(String)

错误

§

Union(Vec<TsValue>)

联合类型

§

Generic(String, Vec<TsValue>)

泛型类型

§

Symbol(String)

符号

§

BigInt(i128)

大整数

§

Date(i64)

日期

§

RegExp(String)

正则表达式

§

Map(Vec<(TsValue, TsValue)>)

Map

§

Set(Vec<TsValue>)

Set

§

Promise(Box<TsValue>)

Promise

§

Iterable(Box<dyn Iterator<Item = TsValue>>)

可迭代对象

§

Conditional(Conditional)

条件类型 T extends U ? X : Y

§

Mapped(Mapped)

映射类型 { [K in keyof T]: V }

§

TemplateLiteral(TemplateLiteral)

模板字面量类型

§

KeyOf(Box<TsValue>)

keyof 类型操作符结果

§

TypeOf(Box<TsValue>)

typeof 类型操作符结果

§

IndexedAccess

索引访问类型 T[K]

Fields

§object_type: Box<TsValue>

对象类型

§index_type: Box<TsValue>

索引类型

§

Tuple(Vec<TsValue>)

元组类型

§

Readonly(Box<TsValue>)

只读类型

§

Nullable(Box<TsValue>)

可空类型 (T | null)

§

NonNullable(Box<TsValue>)

不可空类型 (NonNullable)

§

Infer

推断类型 (infer U)

Fields

§type_param: String

类型参数名称

§constraint: Option<Box<TsValue>>

约束类型

§

FunctionType

函数类型

Fields

§params: Vec<(String, TsValue)>

参数列表

§return_type: Box<TsValue>

返回类型

§

ConstructorType

构造函数类型

Fields

§params: Vec<(String, TsValue)>

参数列表

§return_type: Box<TsValue>

返回类型

§

ThisType

this 类型

§

Never

never 类型

§

Unknown

unknown 类型

§

Any

any 类型

§

Void

void 类型

Implementations§

Source§

impl TsValue

Source

pub fn is_undefined(&self) -> bool

检查是否为未定义

Source

pub fn is_null(&self) -> bool

检查是否为空值

Source

pub fn is_boolean(&self) -> bool

检查是否为布尔值

Source

pub fn is_number(&self) -> bool

检查是否为数字

Source

pub fn is_string(&self) -> bool

检查是否为字符串

Source

pub fn is_object(&self) -> bool

检查是否为对象

Source

pub fn is_array(&self) -> bool

检查是否为数组

Source

pub fn is_function(&self) -> bool

检查是否为函数

Source

pub fn is_error(&self) -> bool

检查是否为错误

Source

pub fn is_union(&self) -> bool

检查是否为联合类型

Source

pub fn is_generic(&self) -> bool

检查是否为泛型类型

Source

pub fn is_symbol(&self) -> bool

检查是否为符号

Source

pub fn is_bigint(&self) -> bool

检查是否为大整数

Source

pub fn is_date(&self) -> bool

检查是否为日期

Source

pub fn is_regexp(&self) -> bool

检查是否为正则表达式

Source

pub fn is_map(&self) -> bool

检查是否为 Map

Source

pub fn is_set(&self) -> bool

检查是否为 Set

Source

pub fn is_promise(&self) -> bool

检查是否为 Promise

Source

pub fn is_iterable(&self) -> bool

检查是否为可迭代对象

Source

pub fn is_conditional(&self) -> bool

检查是否为条件类型

Source

pub fn is_mapped(&self) -> bool

检查是否为映射类型

Source

pub fn is_template_literal(&self) -> bool

检查是否为模板字面量类型

Source

pub fn is_keyof(&self) -> bool

检查是否为 keyof 类型

Source

pub fn is_typeof(&self) -> bool

检查是否为 typeof 类型

Source

pub fn is_indexed_access(&self) -> bool

检查是否为索引访问类型

Source

pub fn is_tuple(&self) -> bool

检查是否为元组类型

Source

pub fn is_readonly(&self) -> bool

检查是否为只读类型

Source

pub fn is_nullable(&self) -> bool

检查是否为可空类型

Source

pub fn is_non_nullable(&self) -> bool

检查是否为不可空类型

Source

pub fn is_infer(&self) -> bool

检查是否为推断类型

Source

pub fn is_function_type(&self) -> bool

检查是否为函数类型

Source

pub fn is_constructor_type(&self) -> bool

检查是否为构造函数类型

Source

pub fn is_this_type(&self) -> bool

检查是否为 this 类型

Source

pub fn is_never(&self) -> bool

检查是否为 never 类型

Source

pub fn is_unknown(&self) -> bool

检查是否为 unknown 类型

Source

pub fn is_any(&self) -> bool

检查是否为 any 类型

Source

pub fn is_void(&self) -> bool

检查是否为 void 类型

Source

pub fn to_boolean(&self) -> bool

转换为布尔值

Source

pub fn to_number(&self) -> f64

转换为数字

Source

pub fn to_string(&self) -> String

转换为字符串

Source

pub fn is_assignable_to(&self, target: &TsValue) -> bool

检查类型是否可赋值给目标类型

Source

pub fn get_property_keys(&self) -> Vec<String>

获取类型的所有属性键

Source

pub fn get_property_type(&self, key: &str) -> Option<TsValue>

获取指定属性的类型

Source

pub fn evaluate_conditional( &self, check_type: &TsValue, extends_type: &TsValue, ) -> Option<bool>

评估条件类型

Source

pub fn infer_type_params(&self, target: &TsValue) -> InferenceResult

推断类型参数

Source

pub fn substitute_type_params( &self, substitutions: &HashMap<String, TsValue>, ) -> TsValue

替换类型参数

Source

pub fn intersection_with(&self, other: &TsValue) -> TsValue

计算两个类型的交集

§参数
  • other: 另一个类型
§返回

两个类型的交集

Source

pub fn difference_with(&self, other: &TsValue) -> TsValue

计算两个类型的差集

§参数
  • other: 要减去的类型
§返回

类型差集

Source

pub fn apply_mapped_type(&self, mapped_type: &Mapped) -> TsValue

应用映射类型到对象

§参数
  • mapped_type: 映射类型
§返回

应用映射后的类型

Source

pub fn is_primitive(&self) -> bool

检查类型是否为原始类型

§返回

如果是原始类型返回 true,否则返回 false

Source

pub fn is_complex(&self) -> bool

检查类型是否为复合类型

§返回

如果是复合类型返回 true,否则返回 false

Source

pub fn type_name(&self) -> String

获取类型的字符串表示

§返回

类型的字符串表示

Source

pub fn simplify(&self) -> TsValue

简化类型

§返回

简化后的类型

Source

pub fn intersect(&self, other: &TsValue) -> TsValue

计算类型交集

Source

pub fn difference(&self, other: &TsValue) -> TsValue

计算类型差集

Source

pub fn is_literal(&self) -> bool

检查类型是否为字面量类型

Source

pub fn get_base_type(&self) -> TsValue

获取类型的基础类型

Source

pub fn is_part_of_union(&self, union: &TsValue) -> bool

检查类型是否为联合类型的一部分

Source

pub fn resolve_keyof(&self) -> TsValue

解析 keyof 类型

Source

pub fn resolve_indexed_access(&self) -> TsValue

解析索引访问类型

Source

pub fn resolve_mapped(&self) -> TsValue

解析映射类型

Trait Implementations§

Source§

impl Clone for TsValue

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TsValue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for TsValue

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for TsValue

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for TsValue

Source§

impl Send for TsValue

Source§

impl Sync for TsValue

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.