Skip to content

Commit a30e35b

Browse files
committed
Check types
1 parent 9dc3b6a commit a30e35b

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ jobs:
2020
run: npm install
2121
- name: Run tests
2222
run: npm run tests-only
23+
types:
24+
name: Typecheck
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Checkout sources
28+
uses: actions/checkout@v4
29+
- name: Install Node.js
30+
uses: actions/setup-node@v4
31+
with:
32+
node-version: lts/*
33+
- name: Install dependencies
34+
run: npm install
35+
- name: Check types
36+
run: npm run types
2337
lint:
2438
name: Lint
2539
runs-on: ubuntu-latest
@@ -32,5 +46,5 @@ jobs:
3246
node-version: lts/*
3347
- name: Install dependencies
3448
run: npm install
35-
- name: Run tests
49+
- name: Check style
3650
run: npm run lint

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"prepare": "npm run build",
4343
"lint": "oxlint src && dprint check",
4444
"tests-only": "node test/test.js",
45-
"test": "npm run build && npm run tests-only && npm run lint"
45+
"test": "npm run build && npm run types && npm run tests-only && npm run lint",
46+
"types": "tsc -p . --noEmit"
4647
},
4748
"typings": "./dist/index.d.ts"
4849
}

src/Importer.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import httpErrors from 'http-errors';
2-
import Client, { PlaylistItemResource, PlaylistResource } from './Client';
2+
import Client, { type PlaylistItemResource, type PlaylistResource } from './Client';
33
import { getBestThumbnail, getPlaylistID, getVideos, type UwMedia } from './util';
44

55
const { BadRequest, NotFound } = httpErrors;
@@ -105,7 +105,11 @@ export default class YouTubeImport {
105105
id: playlistID,
106106
maxResults: 1,
107107
});
108-
return data.items[0];
108+
const [playlist] = data.items;
109+
if (playlist == null) {
110+
throw new NotFound('Playlist not found.');
111+
}
112+
return playlist;
109113
}
110114

111115
async getImportablePlaylist(url: string): Promise<{
@@ -149,11 +153,11 @@ export default class YouTubeImport {
149153
};
150154
let idOptions;
151155
if (match) {
152-
idOptions = { id: match[1] };
156+
idOptions = { id: match[1]! };
153157
} else {
154158
match = url.match(rxUserUrl);
155159
if (match) {
156-
idOptions = { forUsername: match[1] };
160+
idOptions = { forUsername: match[1]! };
157161
} else {
158162
throw new BadRequest(
159163
'Invalid channel URL. Please provide a direct link to the channel or '
@@ -173,7 +177,7 @@ export default class YouTubeImport {
173177
);
174178
}
175179

176-
const channel = data.items[0];
180+
const channel = data.items[0]!;
177181
return {
178182
id: channel.id,
179183
title: channel.snippet.title,

src/util.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import getArtistTitle from 'get-artist-title';
22
import getYouTubeChapters from 'get-youtube-chapters';
33
import getYouTubeID from 'get-youtube-id';
44
import parseIsoDuration from 'parse-iso-duration';
5-
import Client, { Thumbnails, VideoResource } from './Client';
5+
import Client, { type Thumbnails, type VideoResource } from './Client';
66

77
const rxSimplePlaylistUrl = /youtube\.com\/(?:playlist|watch)\?.*?list=([a-z0-9_-]+)/i;
88
const rxPlaylistID = /^([a-z0-9_-]+)$/i;
@@ -17,7 +17,7 @@ export function getPlaylistID(url: string): string | null {
1717

1818
const match = url.match(rxSimplePlaylistUrl);
1919
if (match) {
20-
return match[1];
20+
return match[1]!;
2121
}
2222

2323
return null;
@@ -93,7 +93,7 @@ function convertVideoToMedia(video: VideoResource): UwMedia {
9393
if (index < chapters.length - 1) {
9494
return {
9595
...chapter,
96-
end: chapters[index + 1].start,
96+
end: chapters[index + 1]!.start,
9797
};
9898
}
9999
return {

0 commit comments

Comments
 (0)