Zum Inhalt springen

Mutable Global State (ARCH3187)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

Key typescript.quality.mutable-global-state · Severity warning · Category quality

Module-level mutable shared state creates hidden dependencies and test-isolation problems, and leads to unpredictable behavior under concurrent access. State should be encapsulated or kept immutable.

export let currentUser: User | null = null;
export function login(u: User) {
currentUser = u;
}
export class Session {
private user: User | null = null;
setUser(u: User) { this.user = u; }
getUser() { return this.user; }
}

Encapsulate shared state inside a class/service and inject its instance as a dependency.