File tree Expand file tree Collapse file tree 3 files changed +7
-5
lines changed Expand file tree Collapse file tree 3 files changed +7
-5
lines changed Original file line number Diff line number Diff 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 = "" ;
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import validation from "../utils/validation.js";
33import { TodoItem } from "../types/todo.js" ;
44
55export 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 ) ;
Original file line number Diff line number Diff line change @@ -3,6 +3,6 @@ import { getItem } from "./utils/storage.js";
33
44const initialState = getItem ( "todo" , [ ] ) ;
55const 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 ) ;
You can’t perform that action at this time.
0 commit comments