Skip to content

Commit 1f89653

Browse files
committed
Improve JavaScript
Avoid an error reported by TypeScript 4.1.5 (`href` might be undefined). _javascripts_src/page.ts:6:34 - error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is not assignable to type 'string'. 6 if (current_page.indexOf($(this).attr('href')) == 0) { ~~~~~~~~~~~~~~~~~~~~
1 parent b703e66 commit 1f89653

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

_javascripts_src/page.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ var Page = {
33
highlight: function () {
44
var current_page = location.pathname;
55
$("#header div.site-links a:not(.home)").each(function (i) {
6-
if (current_page.indexOf($(this).attr('href')) == 0) {
6+
let element_href = $(this).attr('href');
7+
if (element_href && current_page.indexOf(element_href) == 0) {
78
$(this).addClass('selected');
89
}
910
});

javascripts/page.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ var Page = {
44
highlight: function () {
55
var current_page = location.pathname;
66
$("#header div.site-links a:not(.home)").each(function (i) {
7-
if (current_page.indexOf($(this).attr('href')) == 0) {
7+
var element_href = $(this).attr('href');
8+
if (element_href && current_page.indexOf(element_href) == 0) {
89
$(this).addClass('selected');
910
}
1011
});

0 commit comments

Comments
 (0)