Skip to content

Commit 50a2ee1

Browse files
committed
Merge remote-tracking branch 'todo-list/main' into yoonseo_working
2 parents 047b9d8 + e249e6a commit 50a2ee1

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/components/TodoForm.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export default class TodoForm {
2020
if (!this.isInit) {
2121
this.$form.addEventListener("submit", (e) => {
2222
e.preventDefault();
23-
const $todo = this.$form.querySelector("input[name=todo]") as HTMLInputElement;
23+
const $todo = this.$form.querySelector<HTMLInputElement>("input[name=todo]");
24+
if (!$todo) return;
2425
const text = $todo.value;
2526
if (text.length > 1) {
2627
$todo.value = "";

src/components/TodoList.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import validation from "../utils/validation.js";
33
import { TodoItem } from "../types/todo.js";
44

55
export default class TodoList {
6-
state: TodoItem[] = [];
6+
state: TodoItem[];
77
private readonly $todoList = document.createElement("div");
88

99
constructor(
@@ -24,7 +24,8 @@ export default class TodoList {
2424

2525
if ($li) {
2626
const newState = [...this.state];
27-
const index = +($li.dataset.index as string);
27+
if (typeof $li.dataset.index !== "string") return;
28+
const index = +$li.dataset.index;
2829

2930
if (target.className === "deleteBtn") {
3031
newState.splice(index, 1);

src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import { getItem } from "./utils/storage.js";
33

44
const initialState = getItem("todo", []);
55
const initialCount = getItem("count", { total: 0, done: 0 });
6-
const $app = document.querySelector("#app") as HTMLElement;
6+
const $app = document.querySelector<HTMLElement>("#app");
77

8-
new App($app, initialState, initialCount);
8+
$app && new App($app, initialState, initialCount);

0 commit comments

Comments
 (0)