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
unknowntype annotation - Return type of functions that could return anything
- Missing
thisparameter type (stricter thanany)
§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
anytype annotation - Arrays with no element type context:
[]defaults toany[] - 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
| Scenario | Use |
|---|---|
| Type resolution failed | ERROR |
| Missing required type annotation | ERROR |
| Failed inference (no fallback) | ERROR |
Explicit unknown annotation | UNKNOWN |
Missing this parameter type | UNKNOWN |
Explicit any annotation | ANY |
Empty array literal [] | any[] |
| Function never returns | NEVER |
| Exhaustive narrowing remainder | NEVER |
Tuple Fields§
§0: u32Implementations§
Source§impl TypeId
impl TypeId
Sourcepub const ERROR: Self
pub const ERROR: Self
Error sentinel - type resolution failed. Propagates through operations to prevent cascading errors. See struct-level docs for detailed semantics.
Sourcepub const NEVER: Self
pub const NEVER: Self
The bottom type - represents values that can never exist. Used for exhaustive checks and functions that never return.
Sourcepub const UNKNOWN: Self
pub const UNKNOWN: Self
TypeScript’s unknown type - type-safe top type.
Requires type narrowing before use. See struct-level docs.
Sourcepub const ANY: Self
pub const ANY: Self
TypeScript’s any type - opts out of type checking.
All operations succeed, returning any. See struct-level docs.
Sourcepub const BOOLEAN_TRUE: Self
pub const BOOLEAN_TRUE: Self
The literal type true.
Sourcepub const BOOLEAN_FALSE: Self
pub const BOOLEAN_FALSE: Self
The literal type false.
Sourcepub const PROMISE_BASE: Self
pub const PROMISE_BASE: Self
Synthetic Promise base type for Promisepromise_like_return_type_argument to extract T from await expressions.
Sourcepub const DELEGATE: Self
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.
Sourcepub const STRICT_ANY: Self
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.
Sourcepub const FIRST_USER: u32 = 100
pub const FIRST_USER: u32 = 100
First user-defined type ID (after built-in intrinsics)
Sourcepub const LOCAL_MASK: u32 = 0x80000000
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.
pub const fn is_intrinsic(self) -> bool
pub fn is_error(self) -> bool
pub fn is_any(self) -> bool
pub fn is_unknown(self) -> bool
pub fn is_never(self) -> bool
Sourcepub fn is_nullish(self) -> bool
pub fn is_nullish(self) -> bool
Returns true if this type is nullish (null or undefined). Useful for strict null checking logic.
Sourcepub fn is_nullable(self) -> bool
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.
Sourcepub fn is_top_type(self) -> bool
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.
Sourcepub fn is_any_or_unknown(self) -> bool
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.
Sourcepub const fn is_local(self) -> bool
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+).
Trait Implementations§
Source§impl From<TypeId> for DiagnosticArg
impl From<TypeId> for DiagnosticArg
impl Copy for TypeId
impl Eq for TypeId
impl StructuralPartialEq for TypeId
Auto Trait Implementations§
impl Freeze for TypeId
impl RefUnwindSafe for TypeId
impl Send for TypeId
impl Sync for TypeId
impl Unpin for TypeId
impl UnsafeUnpin for TypeId
impl UnwindSafe for TypeId
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> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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.