Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit b5cafdf

Browse files
committed
First part of migration to strict types completed 🚀
1 parent b4b569e commit b5cafdf

File tree

8 files changed

+36
-30
lines changed

8 files changed

+36
-30
lines changed

_data/webpack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
hash: 9d713e6c839f73f75474
1+
hash: 4e931446014858453336

_ts/blog/pull-to-refresh.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,7 @@ const getTouchesCoordinatesFrom = (event: TouchEvent): Point => {
4545
)
4646
}
4747

48-
49-
const pullToRefresh = (): void => {
50-
if (!('serviceWorker' in navigator)) {
51-
return
52-
}
53-
54-
const pullToRefreshElement: HTMLElement | null = document.querySelector('#pull-to-refresh')
55-
const pullToRefreshStatusElement: HTMLElement | null = document.querySelector('#pull-to-refresh-status')
56-
const pullToRefreshLoaderElement: HTMLElement | null = document.querySelector('#pull-to-refresh-loader')
57-
const pullableContent: HTMLElement | null = document.querySelector('.pullable-content')
58-
59-
if(!areAllAvailable(pullToRefreshElement, pullToRefreshStatusElement, pullToRefreshLoaderElement, pullableContent)) {
60-
return
61-
}
62-
48+
const startPullToRefresh = (pullToRefreshElement: HTMLElement, pullToRefreshStatusElement: HTMLElement, pullToRefreshLoaderElement: HTMLElement, pullableContent: HTMLElement): void => {
6349
const pullToRefreshElementHeight = 100
6450
const pullToRefreshStatusRepository = createPullToRefreshStatusRepository()
6551
const decelerationFactor = 0.5
@@ -71,7 +57,7 @@ const pullToRefresh = (): void => {
7157
pullToRefreshLoaderElement.style.opacity = `${pullToRefreshLoaderOpacity}`
7258
}
7359

74-
const isDraggingForPullToRefresh = (yMovement): boolean => window.scrollY <= 0 && yMovement <= 0
60+
const isDraggingForPullToRefresh = (yMovement: number): boolean => window.scrollY <= 0 && yMovement <= 0
7561

7662
const closePullToRefresh = (): void => {
7763
addCssClass(pullToRefreshElement, 'end-pull')
@@ -158,4 +144,24 @@ const pullToRefresh = (): void => {
158144
})
159145
}
160146

147+
const pullToRefresh = (): void => {
148+
if (!('serviceWorker' in navigator)) {
149+
return
150+
}
151+
152+
const pullToRefreshElement: HTMLElement | null = document.querySelector<HTMLElement>('#pull-to-refresh')
153+
const pullToRefreshStatusElement: HTMLElement | null = document.querySelector<HTMLElement>('#pull-to-refresh-status')
154+
const pullToRefreshLoaderElement: HTMLElement | null = document.querySelector<HTMLElement>('#pull-to-refresh-loader')
155+
const pullableContent: HTMLElement | null = document.querySelector<HTMLElement>('.pullable-content')
156+
157+
if(areAllAvailable(pullToRefreshElement, pullToRefreshStatusElement, pullToRefreshLoaderElement, pullableContent)) {
158+
startPullToRefresh(
159+
pullToRefreshElement as HTMLElement,
160+
pullToRefreshStatusElement as HTMLElement,
161+
pullToRefreshLoaderElement as HTMLElement,
162+
pullableContent as HTMLElement
163+
)
164+
}
165+
}
166+
161167
export { pullToRefresh }

_ts/common/lazy-load-images.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { addCssClass, removeCssClass } from './css-class'
33

44
const loadImage = (image: HTMLImageElement, observer: IntersectionObserver): void => {
55
const placeholderUrl: string = image.src
6-
image.src = image.dataset.src
6+
image.src = image.dataset.src as string
77
image.onload = (): void => {
88
if (image.src !== placeholderUrl) {
99
observer.unobserve(image)

_ts/home/scene-3D.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const isWebGLEnabled = (): boolean => {
55
try {
66
return !!window.WebGLRenderingContext && (!!c.getContext('experimental-webgl') || !!c.getContext('webgl'));
77
} catch (e) {
8-
return null;
8+
return false;
99
}
1010
}
1111

_ts/home/scene-threejs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ const setWindowResizeListener = (camera: PerspectiveCamera, renderer: WebGLRende
112112
}
113113

114114
const setup = (renderer: WebGLRenderer, camera: PerspectiveCamera, scene: Scene): void => {
115-
document.getElementById('rendering-surface').appendChild(renderer.domElement)
115+
document.getElementById('rendering-surface')?.appendChild(renderer.domElement)
116116
scene.background = new Color(0x303F9F)
117117
setWindowResizeListener(camera, renderer)
118118
}

_ts/home/tabs.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
import { addCssClass, removeCssClass } from '../common/css-class'
22

3-
const forEach = (list: NodeList, operation: (item: Node) => void): void => {
3+
const forEach = (list: NodeListOf<HTMLElement>, operation: (item: HTMLElement) => void): void => {
44
for (let i = 0; i < list.length; i++) {
55
operation(list.item(i))
66
}
77
}
88

9-
const deactivateAll = (tabs: NodeList): void => forEach(tabs, (tab: HTMLElement) => removeCssClass(tab, 'active'))
9+
const deactivateAll = (tabs: NodeListOf<HTMLElement>): void => forEach(tabs, (tab: HTMLElement) => removeCssClass(tab, 'active'))
1010

1111
const activateTabFor = (event: Event): void => {
1212
const element: HTMLElement = (event.currentTarget as HTMLElement)
1313
addCssClass(element, 'active')
1414
}
1515

1616
const deactivateAllTabPanes = (): void => forEach(
17-
document.querySelectorAll('.tab-pane'),
17+
document.querySelectorAll<HTMLElement>('.tab-pane'),
1818
(tabPane: HTMLElement) => removeCssClass(tabPane, 'active')
1919
)
2020

2121
const activateTabPaneFor = (event: Event): void => {
2222
const element: HTMLElement = (event.target as HTMLElement)
2323
const activePaneId: string | null = element.getAttribute('href')
2424
if (activePaneId) {
25-
const activePane: HTMLElement | null = document.querySelector(activePaneId)
25+
const activePane: HTMLElement | null = document.querySelector<HTMLElement>(activePaneId)
2626
if (activePane) {
2727
addCssClass(activePane, 'active')
2828
}
2929
}
3030
}
3131

32-
const tabClick = (tabs: NodeList, event: Event): void => {
32+
const tabClick = (tabs: NodeListOf<HTMLElement>, event: Event): void => {
3333
event.preventDefault()
3434
deactivateAll(tabs)
3535
activateTabFor(event)
@@ -38,7 +38,7 @@ const tabClick = (tabs: NodeList, event: Event): void => {
3838
}
3939

4040
const tabs = (): void => {
41-
const tabs: NodeList = document.querySelectorAll('ul.nav-tabs > li')
41+
const tabs: NodeListOf<HTMLElement> = document.querySelectorAll('ul.nav-tabs > li')
4242
forEach(tabs, (tab: HTMLElement) => {
4343
tab.addEventListener('click', (event: Event) => tabClick(tabs, event))
4444
})

_ts/sw.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ setCatchHandler((options: RouteHandlerCallbackOptions): Promise<Response> => {
6969
const isAOfflinePageImageRequest = (options: RouteHandlerCallbackOptions): boolean =>
7070
!(typeof options.request === 'string') &&
7171
options.request.destination == 'image' &&
72-
options.url.pathname == OFFLINE_PAGE_NO_NETWORK_IMAGE_URL
72+
options.url?.pathname == OFFLINE_PAGE_NO_NETWORK_IMAGE_URL
7373

7474
if (isADocumentRequest(options)) {
75-
return caches.match(OFFLINE_PAGE_URL);
75+
return caches.match(OFFLINE_PAGE_URL) as Promise<Response>;
7676
}
7777

7878
if (isAOfflinePageImageRequest(options)) {
79-
return caches.match(OFFLINE_PAGE_NO_NETWORK_IMAGE_URL);
79+
return caches.match(OFFLINE_PAGE_NO_NETWORK_IMAGE_URL) as Promise<Response>;
8080
}
8181

8282
return Promise.resolve(Response.error());

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"module": "ES2020", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
55
"moduleResolution": "node",
66
"allowJs": true, /* Allow javascript files to be compiled. */
7-
"strict": false, /* Enable all strict type-checking options. */
7+
"strict": true, /* Enable all strict type-checking options. */
88
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
99
"lib": ["esnext", "webworker", "dom"],
1010
"skipLibCheck": true, /* Skip type checking of declaration files. */

0 commit comments

Comments
 (0)