Skip to content

Commit a1b0cd1

Browse files
Enable noUncheckedIndexedAccess in tsconfig.json
1 parent 8436a42 commit a1b0cd1

File tree

7 files changed

+16
-15
lines changed

7 files changed

+16
-15
lines changed

src/camera/core-impl.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,12 @@ class RenderedCameraImpl implements RenderedCamera {
218218
private getFirstTrackOrFail(): MediaStreamTrack {
219219
this.failIfClosed();
220220

221-
if (this.mediaStream.getVideoTracks().length === 0) {
221+
const firstTrack = this.mediaStream.getVideoTracks()[0];
222+
if (!firstTrack) {
222223
throw "No video tracks found";
223-
}
224224

225-
return this.mediaStream.getVideoTracks()[0];
225+
}
226+
return firstTrack;
226227
}
227228

228229
//#region Public APIs.

src/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export class Html5QrcodeConstants {
8989
static DEFAULT_REMEMBER_LAST_CAMERA_USED = true;
9090
static DEFAULT_SUPPORTED_SCAN_TYPE = [
9191
Html5QrcodeScanType.SCAN_TYPE_CAMERA,
92-
Html5QrcodeScanType.SCAN_TYPE_FILE];
92+
Html5QrcodeScanType.SCAN_TYPE_FILE] as const;
9393
}
9494

9595
/** Defines dimension for QR Code Scanner. */

src/html5-qrcode-scanner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export interface Html5QrcodeScannerConfig
114114
* - [SCAN_TYPE_FILE] - Only file based scan supported.
115115
* - Setting wrong values or multiple values will fail.
116116
*/
117-
supportedScanTypes?: Array<Html5QrcodeScanType> | [];
117+
supportedScanTypes?: ReadonlyArray<Html5QrcodeScanType> | [];
118118

119119
/**
120120
* If `true` the rendered UI will have button to turn flash on or off

src/html5-qrcode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,12 +1259,12 @@ export class Html5Qrcode {
12591259
};
12601260

12611261
const keys = Object.keys(cameraIdOrConfig);
1262-
if (keys.length !== 1) {
1262+
const key = keys[0];
1263+
if (!key) {
12631264
throw "'cameraIdOrConfig' object should have exactly 1 key,"
12641265
+ ` if passed as an object, found ${keys.length} keys`;
12651266
}
12661267

1267-
const key:string = Object.keys(cameraIdOrConfig)[0];
12681268
if (key !== facingModeKey && key !== deviceIdKey) {
12691269
throw `Only '${facingModeKey}' and '${deviceIdKey}' `
12701270
+ " are supported for 'cameraIdOrConfig'";

src/ui/scanner/file-selection-ui.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,10 @@ export class FileSelectionUi {
6969
return;
7070
}
7171
let target: HTMLInputElement = e.target as HTMLInputElement;
72-
if (target.files && target.files.length === 0) {
72+
const file = target.files?.[0];
73+
if (!file) {
7374
return;
7475
}
75-
let fileList: FileList = target.files!;
76-
const file: File = fileList[0];
7776
let fileName = file.name;
7877
$this.setImageNameToButton(fileName);
7978

src/ui/scanner/scan-type-selector.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import {
1515

1616
/** Util class to help with scan type selection in scanner class. */
1717
export class ScanTypeSelector {
18-
private supportedScanTypes: Array<Html5QrcodeScanType>;
18+
private supportedScanTypes: readonly [Html5QrcodeScanType, ...Array<Html5QrcodeScanType>];
1919

20-
constructor(supportedScanTypes?: Array<Html5QrcodeScanType> | []) {
20+
constructor(supportedScanTypes?: ReadonlyArray<Html5QrcodeScanType> | []) {
2121
this.supportedScanTypes = this.validateAndReturnScanTypes(
2222
supportedScanTypes);
2323
}
@@ -65,8 +65,8 @@ export class ScanTypeSelector {
6565
* Fails early if the config values is incorrectly set.
6666
*/
6767
private validateAndReturnScanTypes(
68-
supportedScanTypes?:Array<Html5QrcodeScanType>):
69-
Array<Html5QrcodeScanType> {
68+
supportedScanTypes?:ReadonlyArray<Html5QrcodeScanType>):
69+
readonly [Html5QrcodeScanType, ...Array<Html5QrcodeScanType>] {
7070
// If not set, use the default values and order.
7171
if (!supportedScanTypes || supportedScanTypes.length === 0) {
7272
return Html5QrcodeConstants.DEFAULT_SUPPORTED_SCAN_TYPE;
@@ -88,7 +88,7 @@ export class ScanTypeSelector {
8888
}
8989
}
9090

91-
return supportedScanTypes;
91+
return supportedScanTypes as [Html5QrcodeScanType, ...Array<Html5QrcodeScanType>];
9292
}
9393
//#endregion
9494
}

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// Flags to ensure code quality.
1212
"strict": true,
1313
"noImplicitReturns": true,
14+
"noUncheckedIndexedAccess": true,
1415
"noUnusedParameters": true,
1516
"experimentalDecorators": true,
1617
"removeComments": true,

0 commit comments

Comments
 (0)