Fix various type errors with strict mode

This commit is contained in:
Ryan Gossiaux
2021-12-15 14:06:33 -08:00
parent 543c1263e3
commit 5b36ce9404
9 changed files with 96 additions and 64 deletions

View File

@@ -15,9 +15,9 @@
export interface StateDefinition {
dialogState: DialogStates;
titleId: string | null;
titleId?: string;
setTitleId(id: string | null): void;
setTitleId(id?: string): void;
close(): void;
}
@@ -26,9 +26,9 @@
export function useDialogContext(
component: string
): Writable<StateDefinition | undefined> {
): Writable<StateDefinition> {
let context = getContext(DIALOG_CONTEXT_NAME) as
| Writable<StateDefinition | undefined>
| Writable<StateDefinition>
| undefined;
if (context === undefined) {
throw new Error(
@@ -112,14 +112,12 @@
}
});
let titleId: StateDefinition["titleId"] = null;
let titleId: StateDefinition["titleId"];
let api: Writable<StateDefinition | undefined> = writable();
setContext(DIALOG_CONTEXT_NAME, api);
$: api.set({
let api: Writable<StateDefinition> = writable({
titleId,
dialogState,
setTitleId(id: string | null) {
setTitleId(id?: string) {
if (titleId === id) return;
titleId = id;
},
@@ -127,6 +125,14 @@
dispatch("close", false);
},
});
setContext(DIALOG_CONTEXT_NAME, api);
$: api.update((obj) => {
return {
...obj,
titleId,
dialogState,
};
});
// Handle outside click
async function handleWindowMousedown(event: MouseEvent) {
@@ -136,7 +142,7 @@
if (containers.size !== 1) return;
if (contains(containers, target)) return;
$api.close();
$api?.close();
await tick();
target?.focus();
}
@@ -148,7 +154,7 @@
if (containers.size > 1) return; // 1 is myself, otherwise other elements in the Stack
event.preventDefault();
event.stopPropagation();
$api.close();
$api?.close();
}
let mounted = false;
@@ -196,7 +202,7 @@
entry.boundingClientRect.width === 0 &&
entry.boundingClientRect.height === 0
) {
$api.close();
$api?.close();
}
}
});