Conform more code to strict null checking (#10153)

* Conform more code to strict null checking

* Conform more code to strict null checking

* Iterate

* Iterate
This commit is contained in:
Michael Telatynski 2023-02-15 13:36:22 +00:00 committed by GitHub
parent a4ff959aa1
commit 145a5a8a8d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
89 changed files with 520 additions and 551 deletions

View file

@ -55,10 +55,10 @@ export class NotificationUtils {
// "highlight: true/false,
// }
// If the actions couldn't be decoded then returns null.
public static decodeActions(actions: PushRuleAction[]): IEncodedActions {
public static decodeActions(actions: PushRuleAction[]): IEncodedActions | null {
let notify = false;
let sound = null;
let highlight = false;
let sound: string | undefined;
let highlight: boolean | undefined = false;
for (let i = 0; i < actions.length; ++i) {
const action = actions[i];
@ -87,7 +87,7 @@ export class NotificationUtils {
}
const result: IEncodedActions = { notify, highlight };
if (sound !== null) {
if (sound !== undefined) {
result.sound = sound;
}
return result;

View file

@ -62,7 +62,7 @@ export class PushRuleVectorState {
* category or in PushRuleVectorState.LOUD, regardless of its enabled
* state. Returns null if it does not match these categories.
*/
public static contentRuleVectorStateKind(rule: IPushRule): VectorState {
public static contentRuleVectorStateKind(rule: IPushRule): VectorState | null {
const decoded = NotificationUtils.decodeActions(rule.actions);
if (!decoded) {
@ -77,7 +77,7 @@ export class PushRuleVectorState {
if (decoded.highlight) {
tweaks++;
}
let stateKind = null;
let stateKind: VectorState | null = null;
switch (tweaks) {
case 0:
stateKind = VectorState.On;

View file

@ -28,5 +28,5 @@ export class StandardActions {
public static ACTION_HIGHLIGHT = encodeActions({ notify: true, highlight: true });
public static ACTION_HIGHLIGHT_DEFAULT_SOUND = encodeActions({ notify: true, sound: "default", highlight: true });
public static ACTION_DONT_NOTIFY = encodeActions({ notify: false });
public static ACTION_DISABLED: PushRuleAction[] | null = null;
public static ACTION_DISABLED: PushRuleAction[] | undefined = undefined;
}

View file

@ -41,7 +41,7 @@ class VectorPushRuleDefinition {
}
// Translate the rule actions and its enabled value into vector state
public ruleToVectorState(rule: IAnnotatedPushRule): VectorState {
public ruleToVectorState(rule: IAnnotatedPushRule): VectorState | undefined {
let enabled = false;
if (rule) {
enabled = rule.enabled;