Type: Dependencies[K] -- exact dependency type inferred from the key
Success: The dependency value (live reference, not a copy)
Failure: Never returns -- throws ReferenceError
5. Possible Errors
Condition
Error Type
Message
key not a string
TypeError
[router.getDependency]: dependency name must be a string, got {type}
Dependency missing
ReferenceError
[router.getDependency]: dependency "{name}" not found
Error Examples
// TypeError: not a string// @ts-expect-errordepsApi.get(123);// TypeError: [router.getDependency]: dependency name must be a string, got number// ReferenceError: not founddepsApi.get("nonexistent");// ReferenceError: [router.getDependency]: dependency "nonexistent" not found
constdepsApi=getDependenciesApi(router);// get — throws error if missingtry{constservice=depsApi.get("maybeNotExist");}catch(e){// Handle ReferenceError}// has — safe check firstif(depsApi.has("maybeNotExist")){constservice=depsApi.get("maybeNotExist");}
get is a read-only operation. It does not check disposed state and continues to work after router.dispose():
router.dispose();constdepsApi=getDependenciesApi(router);// Read-only methods still workdepsApi.has("foo");depsApi.getAll();
Note: after dispose(), all dependencies are cleared by the cleanup sequence, so get will throw ReferenceError for any key.
8. Migration from router5
Before (router5)
After (real-router)
router.getDependency(name)
getDependenciesApi(router).get(name)
// Before (router5)constapi=router.getDependency("apiClient");// After (real-router)import{getDependenciesApi}from"@real-router/core/api";constdepsApi=getDependenciesApi(router);constapi=depsApi.get("apiClient");