Dynamsoft / barcode-reader-javascript-samples

Samples for Dynamsoft Barcode Reader Javascript edition
https://www.dynamsoft.com/barcode-reader/sdk-javascript/
18 stars 36 forks source link

Export interface for VideoDeviceInfo #210

Open qidulak opened 5 days ago

qidulak commented 5 days ago

Interface VideoDeviceInfo that is returned by BarcodeScanner.getAllCameras() is not publicly exported, so I need to define it on my own, If I want to make some logic and further process this data. I believe, that Interfaces returned by all public methods should be exported for strongly typped app.

Keillion commented 5 days ago

We will consider your suggestion carefully.

Currently, you can simply implement your needs in this way.

let videoInfos: ReturnType<typeof BarcodeScanner.getAllCameras> = null;
let videoInfo: ReturnType<typeof BarcodeScanner.getAllCameras>[0] = null;
// assign later
Keillion commented 5 days ago

I tested, at least in dynamsoft-camera-enhancer@4.0.3 or dynamsoft-barcode-reader-bundle@10.2.1000, VideoDeviceInfo is exported.

import { VideoDeviceInfo } from 'dynamsoft-camera-enhancer';
// or
import { VideoDeviceInfo } from 'dynamsoft-barcode-reader-bundle';
Keillion commented 5 days ago

Oh, I know you use dynamsoft-javascript-barcode@9.

In dynamsoft-javascript-barcode@9.6.42, VideoDeviceInfo is exported.

You can consider upgrading to the latest version 9, which is mainly adapted for the latest iOS to improve camera selection.

dobripet commented 4 days ago

I did check dynamsoft-javascript-barcode@9.6.42 dbr.d.ts file. VideoDeviceInfo is declared there but missing in exports. So it cannot be referenced via import.

image

The workaround by return type needs to be tweaked as it is promise and that is kind of messy.

type VideoDeviceInfo = Awaited<ReturnType<BarcodeScanner['getAllCameras']>>[number];

But as you said VideoDeviceInfo import works for dynamsoft-camera-enhancer which comes with dynamsoft-javascript-barcode so I guess its fine to import it from there, thank you.