Skip to main content

TypeId

Struct TypeId 

Source
pub struct TypeId(pub u32);
Expand description

A lightweight handle to an interned type. Equality check is O(1) - just compare the u32 values.

§Sentinel Value Semantics

The following sentinel values have specific semantics for error handling and type inference:

§TypeId::ERROR

Used when type resolution fails due to an actual error:

  • Missing AST nodes or invalid syntax
  • Type annotation that cannot be resolved
  • Failed type inference with no fallback

Error propagation: ERROR is “contagious” - operations on ERROR types return ERROR. This prevents cascading errors from a single root cause. Property access on ERROR returns ERROR silently (no additional diagnostics emitted).

Example uses:

  • Missing type annotation: let x; -> ERROR (prevents “any poisoning”)
  • Failed generic inference with no constraint/default
  • Invalid type syntax or unresolved type references

§TypeId::UNKNOWN

The TypeScript unknown type - a type-safe alternative to any. Use when the type is genuinely unknown at compile time, but should be checked before use.

Strict behavior: Property access on UNKNOWN returns IsUnknown result, which the checker reports as TS2571 “Object is of type ‘unknown’”.

Example uses:

  • Explicit unknown type annotation
  • Return type of functions that could return anything
  • Missing this parameter type (stricter than any)

§TypeId::ANY

The TypeScript any type - opts out of type checking entirely. Use for intentional any-typed values or interop with untyped code.

Permissive behavior: Property access on ANY succeeds and returns ANY. No type errors are produced for any-typed expressions.

Example uses:

  • Explicit any type annotation
  • Arrays with no element type context: [] defaults to any[]
  • Interop with JavaScript libraries without type definitions

§TypeId::NEVER

The bottom type - represents values that can never exist. Used for exhaustive checking and functions that never return.

Example uses:

  • Function that always throws or loops forever
  • Exhaustive switch/if narrowing (remaining type after all cases)
  • Intersection of incompatible types

§Summary: When to Use Each

ScenarioUse
Type resolution failedERROR
Missing required type annotationERROR
Failed inference (no fallback)ERROR
Explicit unknown annotationUNKNOWN
Missing this parameter typeUNKNOWN
Explicit any annotationANY
Empty array literal []any[]
Function never returnsNEVER
Exhaustive narrowing remainderNEVER

Tuple Fields§

§0: u32

Implementations§

Source§

impl TypeId

Source

pub const NONE: Self

Internal placeholder - no valid type.

Source

pub const ERROR: Self

Error sentinel - type resolution failed. Propagates through operations to prevent cascading errors. See struct-level docs for detailed semantics.

Source

pub const NEVER: Self

The bottom type - represents values that can never exist. Used for exhaustive checks and functions that never return.

Source

pub const UNKNOWN: Self

TypeScript’s unknown type - type-safe top type. Requires type narrowing before use. See struct-level docs.

Source

pub const ANY: Self

TypeScript’s any type - opts out of type checking. All operations succeed, returning any. See struct-level docs.

Source

pub const VOID: Self

The void type - used for functions with no meaningful return.

Source

pub const UNDEFINED: Self

The undefined type - represents the undefined value.

Source

pub const NULL: Self

The null type - represents the null value.

Source

pub const BOOLEAN: Self

The boolean type - union of true | false.

Source

pub const NUMBER: Self

The number type - all numeric values.

Source

pub const STRING: Self

The string type - all string values.

Source

pub const BIGINT: Self

The bigint type - arbitrary precision integers.

Source

pub const SYMBOL: Self

The symbol type - unique symbol values.

Source

pub const OBJECT: Self

The object type - any non-primitive value.

Source

pub const BOOLEAN_TRUE: Self

The literal type true.

Source

pub const BOOLEAN_FALSE: Self

The literal type false.

Source

pub const FUNCTION: Self

The Function type - any callable.

Source

pub const PROMISE_BASE: Self

Synthetic Promise base type for Promise when Promise symbol is not resolved. Used to allow promise_like_return_type_argument to extract T from await expressions.

Source

pub const DELEGATE: Self

Internal sentinel indicating that expression checking should be delegated to CheckerState for complex cases that need full checker context. This is NOT a real type and should never escape ExpressionChecker/CheckerState.

Source

pub const STRICT_ANY: Self

Internal sentinel used to represent ‘any’ in strict mode (North Star Fix). Behaves like ‘any’ but does NOT silence structural mismatches.

Source

pub const FIRST_USER: u32 = 100

First user-defined type ID (after built-in intrinsics)

Source

pub const LOCAL_MASK: u32 = 0x80000000

Mask for the local bit (MSB of u32).

Local IDs have MSB=1 (0x80000000+), Global IDs have MSB=0 (0x7FFFFFFF-). This partitioning allows ScopedTypeInterner to create ephemeral types that don’t pollute the global TypeId space.

Source

pub const fn is_intrinsic(self) -> bool

Source

pub fn is_error(self) -> bool

Source

pub fn is_any(self) -> bool

Source

pub fn is_unknown(self) -> bool

Source

pub fn is_never(self) -> bool

Source

pub fn is_nullish(self) -> bool

Returns true if this type is nullish (null or undefined). Useful for strict null checking logic.

Source

pub fn is_nullable(self) -> bool

Returns true if this type is nullable (null, undefined, or void). VOID is considered nullable because it represents undefined in some contexts.

Source

pub fn is_top_type(self) -> bool

Returns true if this type is a top type (any or unknown). Top types are assignable from all other types.

Source

pub fn is_any_or_unknown(self) -> bool

Returns true if this type is any or unknown (types that accept anything). Alias for is_top_type for clarity in some contexts.

Source

pub const fn is_local(self) -> bool

Check if this TypeId is a local (ephemeral) type.

Local types are created by ScopedTypeInterner and are only valid for the current operation/request. They are automatically freed when the ScopedTypeInterner is dropped.

Returns true if MSB is set (0x80000000+).

Source

pub const fn is_global(self) -> bool

Check if this TypeId is a global (persistent) type.

Global types are managed by TypeInterner and persist for the lifetime of the project/server. These include declarations and intrinsics.

Returns true if MSB is clear (0x7FFFFFFF-).

Trait Implementations§

Source§

impl Clone for TypeId

Source§

fn clone(&self) -> TypeId

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 TypeId

Source§

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

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

impl Default for TypeId

Source§

fn default() -> TypeId

Returns the “default value” for a type. Read more
Source§

impl From<TypeId> for DiagnosticArg

Source§

fn from(v: TypeId) -> Self

Converts to this type from the input type.
Source§

impl Hash for TypeId

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 TypeId

Source§

fn eq(&self, other: &TypeId) -> 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 Serialize for TypeId

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TypeIdExt for TypeId

Source§

fn non_never(self) -> Option<Self>

Returns Some(self) if self is not NEVER, otherwise None. Read more
Source§

impl Copy for TypeId

Source§

impl Eq for TypeId

Source§

impl StructuralPartialEq for TypeId

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more