Skip to content

Commit 3964ce6

Browse files
committed
chore: update @svelte/tsconfig
The default config has stricter checks for the type system. So we need to make changes across the codebase to fix these issues.
1 parent 0803385 commit 3964ce6

26 files changed

+123
-166
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
"author": "Jamie Brynes",
1414
"license": "ISC",
1515
"dependencies": {
16-
"camelize": "^1.0.1",
16+
"camelize-ts": "^3.0.0",
1717
"moment": "^2.29.4",
1818
"obsidian": "0.15",
19-
"snakeize": "^0.1.0",
19+
"snakify-ts": "^2.3.0",
2020
"svelte": "^4.2.10",
2121
"svelte-select": "^5.0.1",
2222
"tslib": "^2.4.1",
@@ -26,7 +26,7 @@
2626
"@rollup/plugin-commonjs": "^24.0.0",
2727
"@rollup/plugin-node-resolve": "^15.0.1",
2828
"@rollup/plugin-typescript": "^10.0.1",
29-
"@tsconfig/svelte": "^3.0.0",
29+
"@tsconfig/svelte": "^5.0.0",
3030
"@types/chai": "^4.3.4",
3131
"@types/mocha": "^10.0.1",
3232
"@types/node": "^18.11.17",

src/api/fetcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export interface WebFetcher {
55
export type RequestParams = {
66
url: string,
77
method: string,
8-
headers?: Record<string, string>,
8+
headers: Record<string, string>,
99
body?: string,
1010
};
1111

src/api/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import type { Project } from "./domain/project";
44
import type { Section } from "./domain/section";
55
import type { CreateTaskParams, Task, TaskId } from "./domain/task";
66
import type { RequestParams, WebFetcher, WebResponse } from "./fetcher";
7-
import camelize from "camelize";
8-
import snakeize from "snakeize";
7+
import camelize from "camelize-ts";
8+
import snakify from "snakify-ts";
99

1010
export class TodoistApiClient {
1111
private token: string;
@@ -29,7 +29,7 @@ export class TodoistApiClient {
2929
}
3030

3131
public async createTask(content: string, options?: CreateTaskParams): Promise<void> {
32-
const body = snakeize({ content: content, ...(options ?? {}) });
32+
const body = snakify({ content: content, ...(options ?? {}) });
3333
await this.do("/tasks", "POST", body);
3434
}
3535

src/components/MarkdownRenderer.svelte

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts">
22
import { MarkdownRenderer } from "obsidian";
33
import { onMount } from "svelte";
4+
import { getComponent } from "../ui/contexts";
45
56
export let content: string;
67
@@ -9,17 +10,19 @@
910
1011
let containerEl: HTMLDivElement;
1112
13+
const component = getComponent();
14+
1215
onMount(async () => {
13-
await MarkdownRenderer.renderMarkdown(content, containerEl, "", null);
16+
await MarkdownRenderer.renderMarkdown(content, containerEl, "", component);
1417
1518
if (containerEl.childElementCount > 1) {
1619
return;
1720
}
1821
1922
const markdownContent = containerEl.querySelector("p");
2023
21-
if (markdownContent) {
22-
markdownContent.parentElement.removeChild(markdownContent);
24+
if (markdownContent !== null) {
25+
markdownContent.parentElement?.removeChild(markdownContent);
2326
containerEl.innerHTML = markdownContent.innerHTML;
2427
}
2528
});

src/contextMenu.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function showTaskContext(
3333
.setIcon("popup-open")
3434
.onClick(() =>
3535
openExternal(
36-
`https://todoist.com/app/project/${taskCtx.task.project.id}/task/${taskCtx.task.id}`
36+
`https://todoist.com/app/project/${taskCtx.task.project?.id}/task/${taskCtx.task.id}`
3737
)
3838
)
3939
)

src/data/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export class TodoistAdapter {
129129

130130
project: project,
131131
section: section,
132-
parentId: apiTask.parentId,
132+
parentId: apiTask.parentId ?? undefined,
133133

134134
labels: apiTask.labels,
135135
priority: apiTask.priority,

src/data/transformations.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { SortingVariant } from "../query/query";
88
function makeTask(id: string, opts?: Partial<Task>): Task {
99
return {
1010
id,
11-
createdAt: opts?.createdAt,
11+
createdAt: opts?.createdAt ?? "1970-01-01",
1212
parentId: opts?.parentId,
1313
content: "",
1414
description: "",

src/data/transformations.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function groupByProject(tasks: Task[]): GroupedTasks[] {
2828
}
2929

3030
const tasks = projects.get(project);
31-
tasks.push(task);
31+
tasks!.push(task);
3232
}
3333

3434
return Array.from(projects.entries()).map(([project, tasks]) => { return { project: project, tasks: tasks }; })
@@ -91,8 +91,8 @@ function compareTaskDate<T extends Task>(self: T, other: T): number {
9191
return 0;
9292
}
9393

94-
const selfDate = selfInfo.m;
95-
const otherDate = otherInfo.m;
94+
const selfDate = selfInfo.m!;
95+
const otherDate = otherInfo.m!;
9696

9797
// Then lets check if we are the same day, if not
9898
// sort just based on the day.
@@ -140,9 +140,11 @@ export function buildTaskTree(tasks: Task[]): TaskTree[] {
140140
}
141141

142142
const parent = mapping.get(task.parentId);
143-
const child = mapping.get(task.id);
144-
parent.children.push(child)
143+
if (parent !== undefined) {
144+
const child = mapping.get(task.id);
145+
parent.children.push(child!)
146+
}
145147
}
146148

147-
return roots.map(id => mapping.get(id));
149+
return roots.map(id => mapping.get(id)!);
148150
}

src/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { settings, SettingsTab } from "./settings";
22
import type { ISettings } from "./settings";
33
import debug from "./log";
4-
import { App, Plugin, requestUrl } from "obsidian";
4+
import { App, Notice, Plugin, requestUrl } from "obsidian";
55
import type { PluginManifest } from "obsidian";
66
import TodoistApiTokenModal from "./modals/enterToken/enterTokenModal";
77
import CreateTaskModal from "./modals/createTask/createTaskModal";
@@ -48,6 +48,11 @@ export default class TodoistPlugin extends Plugin {
4848
id: "todoist-add-task",
4949
name: "Add Todoist task",
5050
callback: () => {
51+
if (this.options === null) {
52+
new Notice("Failed to load settings, cannot open task creation modal.");
53+
return;
54+
}
55+
5156
new CreateTaskModal(
5257
this.app,
5358
this.todoistAdapter,
@@ -61,6 +66,11 @@ export default class TodoistPlugin extends Plugin {
6166
id: "todoist-add-task-current-page",
6267
name: "Add Todoist task with the current page",
6368
callback: () => {
69+
if (this.options === null) {
70+
new Notice("Failed to load settings, cannot open task creation modal.");
71+
return;
72+
}
73+
6474
new CreateTaskModal(
6575
this.app,
6676
this.todoistAdapter,

src/log.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let _settings: ISettings | undefined = undefined;
55
settings.subscribe((update) => _settings = update);
66

77
export default function debug(log: string | LogMessage) {
8-
if (!_settings.debugLogging) {
8+
if (!_settings?.debugLogging ?? false) {
99
return;
1010
}
1111

0 commit comments

Comments
 (0)