1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-23 17:02:25 +03:00

Apply more strict typescript around the codebase (#2778)

* Apply more strict typescript around the codebase

* Fix tests

* Revert strict mode commit

* Iterate strict

* Iterate

* Iterate strict

* Iterate

* Fix tests

* Iterate

* Iterate strict

* Add tests

* Iterate

* Iterate

* Fix tests

* Fix tests

* Strict types be strict

* Fix types

* detectOpenHandles

* Strict

* Fix client not stopping

* Add sync peeking tests

* Make test happier

* More strict

* Iterate

* Stabilise

* Moar strictness

* Improve coverage

* Fix types

* Fix types

* Improve types further

* Fix types

* Improve typing of NamespacedValue

* Fix types
This commit is contained in:
Michael Telatynski
2022-10-21 11:44:40 +01:00
committed by GitHub
parent fdbbd9bca4
commit 867a0ca7ee
94 changed files with 1980 additions and 1735 deletions

View File

@@ -23,7 +23,10 @@ import { Optional } from "matrix-events-sdk/lib/types";
export class NamespacedValue<S extends string, U extends string> {
// Stable is optional, but one of the two parameters is required, hence the weird-looking types.
// Goal is to to have developers explicitly say there is no stable value (if applicable).
public constructor(public readonly stable: S | null | undefined, public readonly unstable?: U) {
public constructor(stable: S, unstable: U);
public constructor(stable: S, unstable?: U);
public constructor(stable: null | undefined, unstable: U);
public constructor(public readonly stable?: S | null, public readonly unstable?: U) {
if (!this.unstable && !this.stable) {
throw new Error("One of stable or unstable values must be supplied");
}
@@ -33,10 +36,10 @@ export class NamespacedValue<S extends string, U extends string> {
if (this.stable) {
return this.stable;
}
return this.unstable;
return this.unstable!;
}
public get altName(): U | S | null {
public get altName(): U | S | null | undefined {
if (!this.stable) {
return null;
}
@@ -57,7 +60,7 @@ export class NamespacedValue<S extends string, U extends string> {
// this desperately wants https://github.com/microsoft/TypeScript/pull/26349 at the top level of the class
// so we can instantiate `NamespacedValue<string, _, _>` as a default type for that namespace.
public findIn<T>(obj: any): Optional<T> {
let val: T;
let val: T | undefined = undefined;
if (this.name) {
val = obj?.[this.name];
}
@@ -91,7 +94,7 @@ export class ServerControlledNamespacedValue<S extends string, U extends string>
if (this.stable && !this.preferUnstable) {
return this.stable;
}
return this.unstable;
return this.unstable!;
}
}
@@ -109,10 +112,10 @@ export class UnstableValue<S extends string, U extends string> extends Namespace
}
public get name(): U {
return this.unstable;
return this.unstable!;
}
public get altName(): S {
return this.stable;
return this.stable!;
}
}