-
Notifications
You must be signed in to change notification settings - Fork 138
Open
Description
UIRouterGlobals.transition type is incorrectly non-nullable
Summary
The UIRouterGlobals.transition property is typed as non-nullable (Transition), but at runtime it is null or undefined when there is no active transition (e.g., after a state has fully loaded or on initial page load).
Version
@uirouter/core: 6.1.1
Current Type Definition
export class UIRouterGlobals {
transition: Transition;
// ... other properties
}Expected Type Definition
export class UIRouterGlobals {
transition: Transition | null | undefined;
// ... other properties
}Reproduction
Code Example
import { UIRouterGlobals } from '@uirouter/core';
// In an Angular component during ngOnInit, after the state has loaded:
constructor(private uiRouterGlobals: UIRouterGlobals) {}
ngOnInit(): void {
// This throws: "can't access property 'to', this.uiRouterGlobals.transition is null"
const stateName = this.uiRouterGlobals.transition.to().name;
}Root Cause
When no transition is currently active (which is the normal state after a route has finished loading), uiRouterGlobals.transition is null or undefined. The TypeScript type definition incorrectly claims this property is always present, leading to runtime errors when developers follow the types.
Expected Behavior
The type definition should accurately reflect runtime behavior, allowing TypeScript to catch potential null reference errors at compile time.
Metadata
Metadata
Assignees
Labels
No labels