Skip to content

Commit b0a2acc

Browse files
Merge PR mebjas#829 from upstream
2 parents 71c89d3 + 1f95e04 commit b0a2acc

File tree

8 files changed

+20
-19
lines changed

8 files changed

+20
-19
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
@@ -112,7 +112,7 @@ export interface Html5QrcodeScannerConfig
112112
* - [SCAN_TYPE_FILE] - Only file based scan supported.
113113
* - Setting wrong values or multiple values will fail.
114114
*/
115-
supportedScanTypes?: Array<Html5QrcodeScanType> | [];
115+
supportedScanTypes?: ReadonlyArray<Html5QrcodeScanType> | [];
116116

117117
/**
118118
* 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
@@ -1280,12 +1280,12 @@ export class Html5Qrcode {
12801280
};
12811281

12821282
const keys = Object.keys(cameraIdOrConfig);
1283-
if (keys.length !== 1) {
1283+
const key = keys[0];
1284+
if (!key) {
12841285
throw "'cameraIdOrConfig' object should have exactly 1 key,"
12851286
+ ` if passed as an object, found ${keys.length} keys`;
12861287
}
12871288

1288-
const key:string = Object.keys(cameraIdOrConfig)[0];
12891289
if (key !== facingModeKey && key !== deviceIdKey) {
12901290
throw `Only '${facingModeKey}' and '${deviceIdKey}' `
12911291
+ " 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
}

tests/ui/scanner/camera-selection-ui.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ describe("CameraSelectionUi setting and getting values", () => {
123123
let cameraSelectUi = CameraSelectionUi.create(parentElement!, cameras);
124124

125125
// First camera is default.
126-
expect(cameraSelectUi.getValue()).eq(cameras[0].id);
126+
expect(cameraSelectUi.getValue()).eq(cameras[0]!.id);
127127

128-
cameraSelectUi.setValue(cameras[1].id);
129-
expect(cameraSelectUi.getValue()).eq(cameras[1].id);
128+
cameraSelectUi.setValue(cameras[1]!.id);
129+
expect(cameraSelectUi.getValue()).eq(cameras[1]!.id);
130130

131131
expect(() => {
132132
cameraSelectUi.setValue("random string");
@@ -138,7 +138,7 @@ describe("CameraSelectionUi setting and getting values", () => {
138138
let cameras = createCameraList(numCameras);
139139
let cameraSelectUi = CameraSelectionUi.create(parentElement!, cameras);
140140

141-
expect(cameraSelectUi.hasValue(cameras[1].id)).to.be.true;
141+
expect(cameraSelectUi.hasValue(cameras[1]!.id)).to.be.true;
142142
expect(cameraSelectUi.hasValue("random string")).to.be.false;
143143
});
144144
});

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)