Repository: huggingface/transformers.js (language: javascript)

Issue:
3.1.2 typescript build errors
### System Info

transformers.js: 3.1.2
node: 22.12.0
typescript: 5.7.2

### Environment/Platform

- [X] Website/web-app
- [ ] Browser extension
- [ ] Server-side (e.g., Node.js, Deno, Bun)
- [ ] Desktop app (e.g., Electron)
- [ ] Other (e.g., VSCode extension)

### Description

Running a very basic typescript build using transformers.js 3.1.2 will fail.

### Reproduction

package.json
```json
{
  "devDependencies": {
    "@huggingface/transformers": "^3.1.2"
  }
}
```

tsconfig.json
```json
{
  "compilerOptions": {
    "target": "ESNEXT",
    "lib": ["ESNext", "WebWorker"],
    "module": "ESNext",
    "moduleResolution": "bundler",
    "baseUrl": "./",
    "paths": {}
  }
}
```

Main.mts:
```ts
import { AutomaticSpeechRecognitionConfig, env, pipeline, ProgressCallback } from "@huggingface/transformers";
```

runnig `tsc` will fail with following errors

```
node_modules/@huggingface/transformers/types/models/auto/processing_auto.d.ts:32:76 - error TS2304: Cannot find name 'PretrainedProcessorOptions'.

32     static from_pretrained(pretrained_model_name_or_path: string, options: PretrainedProcessorOptions): Promise<Processor>;
                                                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@huggingface/transformers/types/models/mgp_str/processing_mgp_str.d.ts:52:5 - error TS2416: Property 'batch_decode' in type 'MgpstrProcessor' is not assignable to the same property in base type 'Processor'.
  Type '([char_logits, bpe_logits, wp_logits]: Tensor[]) => { generated_text: string[]; scores: number[]; char_preds: string[]; bpe_preds: string[]; wp_preds: string[]; }' is not assignable to type '(...args: any[]) => string[]'.
    Type '{ generated_text: string[]; scores: number[]; char_preds: string[]; bpe_preds: string[]; wp_preds: string[]; }' is missing the following properties from type 'string[]': length, pop, push, concat, and 35 more.

52     batch_decode([char_logits, bpe_logits, wp_logits]: import("../../utils/tensor.js").Tensor[]): {
       ~~~~~~~~~~~~

node_modules/@huggingface/transformers/types/utils/image.d.ts:24:31 - error TS2304: Cannot find name 'HTMLCanvasElement'.

24     static fromCanvas(canvas: HTMLCanvasElement | OffscreenCanvas): RawImage;
                                 ~~~~~~~~~~~~~~~~~

node_modules/onnxruntime-common/dist/esm/tensor-factory.d.ts:203:29 - error TS2304: Cannot find name 'HTMLImageElement'.

203     fromImage(imageElement: HTMLImageElement, options?: TensorFromImageElementOptions): Promise<TypedTensor<'float32'> | TypedTensor<'uint8'>>;
                                ~~~~~~~~~~~~~~~~


Found 4 errors in 4 files.

Errors  Files
     1  node_modules/@huggingface/transformers/types/models/auto/processing_auto.d.ts:32
     1  node_modules/@huggingface/transformers/types/models/mgp_str/processing_mgp_str.d.ts:52
     1  node_modules/@huggingface/transformers/types/utils/image.d.ts:24
     1  node_modules/onnxruntime-common/dist/esm/tensor-factory.d.ts:203
```




Discussion / hints:
I seem to have the same problem. 

this is [reproduction](https://github.com/Debbl/starter-ts/tree/reproduction/huggingface-transformers).
- pnpm install
- pnpm build

There is a file use the `ProgressInfo` type.
<img width="823" alt="image" src="https://github.com/user-attachments/assets/807e39e1-414b-4a87-8cb0-96975d5e437b" />

but it has a type error when run build.

<img width="1393" alt="image" src="https://github.com/user-attachments/assets/38a179b1-48e6-4c75-9bec-840cdb52a350" />

If use `ProgressInfo` like this.
<img width="771" alt="image" src="https://github.com/user-attachments/assets/25bc3d21-d23b-4647-9e9c-770c9c24b62f" />

it can right export.
<img width="1348" alt="image" src="https://github.com/user-attachments/assets/0e0f1485-1914-48ac-902c-28348762147f" />




Fix patch:
diff --git a/src/base/feature_extraction_utils.js b/src/base/feature_extraction_utils.js
index 53a5e4941..300f5ea1d 100644
--- a/src/base/feature_extraction_utils.js
+++ b/src/base/feature_extraction_utils.js
@@ -17,23 +17,23 @@ export class FeatureExtractor extends Callable {
     }
 
     /**
-     * Instantiate one of the processor classes of the library from a pretrained model.
+     * Instantiate one of the feature extractor classes of the library from a pretrained model.
      * 
-     * The processor class to instantiate is selected based on the `image_processor_type` (or `feature_extractor_type`; legacy)
-     * property of the config object (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible)
+     * The feature extractor class to instantiate is selected based on the `feature_extractor_type` property of
+     * the config object (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible)
      * 
      * @param {string} pretrained_model_name_or_path The name or path of the pretrained model. Can be either:
-     * - A string, the *model id* of a pretrained processor hosted inside a model repo on huggingface.co.
+     * - A string, the *model id* of a pretrained feature_extractor hosted inside a model repo on huggingface.co.
      *   Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced under a
      *   user or organization name, like `dbmdz/bert-base-german-cased`.
-     * - A path to a *directory* containing processor files, e.g., `./my_model_directory/`.
-     * @param {import('../utils/hub.js').PretrainedOptions} options Additional options for loading the processor.
+     * - A path to a *directory* containing feature_extractor files, e.g., `./my_model_directory/`.
+     * @param {import('../utils/hub.js').PretrainedOptions} options Additional options for loading the feature_extractor.
      * 
-     * @returns {Promise<FeatureExtractor>} A new instance of the Processor class.
+     * @returns {Promise<FeatureExtractor>} A new instance of the Feature Extractor class.
      */
     static async from_pretrained(pretrained_model_name_or_path, options) {
-        const preprocessorConfig = await getModelJSON(pretrained_model_name_or_path, FEATURE_EXTRACTOR_NAME, true, options);
-        return new this(preprocessorConfig);
+        const config = await getModelJSON(pretrained_model_name_or_path, FEATURE_EXTRACTOR_NAME, true, options);
+        return new this(config);
     }
 }
 
diff --git a/src/base/processing_utils.js b/src/base/processing_utils.js
index ecc1c6155..321f5cdb8 100644
--- a/src/base/processing_utils.js
+++ b/src/base/processing_utils.js
@@ -121,8 +121,8 @@ export class Processor extends Callable {
     /**
      * Instantiate one of the processor classes of the library from a pretrained model.
      * 
-     * The processor class to instantiate is selected based on the `feature_extractor_type` property of the config object
-     * (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible)
+     * The processor class to instantiate is selected based on the `image_processor_type` (or `feature_extractor_type`; legacy)
+     * property of the config object (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible)
      * 
      * @param {string} pretrained_model_name_or_path The name or path of the pretrained model. Can be either:
      * - A string, the *model id* of a pretrained processor hosted inside a model repo on huggingface.co.
diff --git a/src/models/auto/feature_extraction_auto.js b/src/models/auto/feature_extraction_auto.js
index 5a18eabb9..7429d1d54 100644
--- a/src/models/auto/feature_extraction_auto.js
+++ b/src/models/auto/feature_extraction_auto.js
@@ -6,22 +6,6 @@ import * as AllFeatureExtractors from '../feature_extractors.js';
 
 export class AutoFeatureExtractor {
 
-    /**
-     * Instantiate one of the feature extractor classes of the library from a pretrained model.
-     * 
-     * The processor class to instantiate is selected based on the `feature_extractor_type` property of
-     * the config object (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible)
-     * 
-     * @param {string} pretrained_model_name_or_path The name or path of the pretrained model. Can be either:
-     * - A string, the *model id* of a pretrained processor hosted inside a model repo on huggingface.co.
-     *   Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced under a
-     *   user or organization name, like `dbmdz/bert-base-german-cased`.
-     * - A path to a *directory* containing processor files, e.g., `./my_model_directory/`.
-     * @param {import('../../utils/hub.js').PretrainedOptions} options Additional options for loading the processor.
-     * 
-     * @returns {Promise<AllFeatureExtractors.ImageProcessor>} A new instance of the Processor class.
-     */
-
     /** @type {typeof FeatureExtractor.from_pretrained} */
     static async from_pretrained(pretrained_model_name_or_path, options={}) {
 
diff --git a/src/models/auto/processing_auto.js b/src/models/auto/processing_auto.js
index 3b462b6e9..48d6a1524 100644
--- a/src/models/auto/processing_auto.js
+++ b/src/models/auto/processing_auto.js
@@ -40,22 +40,6 @@ import * as AllFeatureExtractors from '../feature_extractors.js';
  */
 export class AutoProcessor {
 
-    /**
-     * Instantiate one of the processor classes of the library from a pretrained model.
-     * 
-     * The processor class to instantiate is selected based on the `image_processor_type` (or `feature_extractor_type`; legacy)
-     * property of the config object (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible)
-     * 
-     * @param {string} pretrained_model_name_or_path The name or path of the pretrained model. Can be either:
-     * - A string, the *model id* of a pretrained processor hosted inside a model repo on huggingface.co.
-     *   Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced under a
-     *   user or organization name, like `dbmdz/bert-base-german-cased`.
-     * - A path to a *directory* containing processor files, e.g., `./my_model_directory/`.
-     * @param {import('../../utils/hub.js').PretrainedOptions} options Additional options for loading the processor.
-     * 
-     * @returns {Promise<Processor>} A new instance of the Processor class.
-     */
-
     /** @type {typeof Processor.from_pretrained} */
     static async from_pretrained(pretrained_model_name_or_path, options={}) {
 
diff --git a/src/models/phi3_v/processing_phi3_v.js b/src/models/phi3_v/processing_phi3_v.js
index d07e9b176..02adae5fe 100644
--- a/src/models/phi3_v/processing_phi3_v.js
+++ b/src/models/phi3_v/processing_phi3_v.js
@@ -14,7 +14,7 @@ export class Phi3VProcessor extends Processor {
      * 
      * @param {string|string[]} text 
      * @param {RawImage|RawImage[]} images 
-     * @param  {...any} args 
+     * @param  { { padding?: boolean, truncation?: boolean, num_crops?: number } | undefined } options
      * @returns {Promise<any>}
      */
     async _call(text, images = null, {
diff --git a/src/pipelines.js b/src/pipelines.js
index 1e54593b6..fcf29c8d5 100644
--- a/src/pipelines.js
+++ b/src/pipelines.js
@@ -1916,7 +1916,7 @@ export class AutomaticSpeechRecognitionPipeline extends (/** @type {new (options
             const max_new_tokens = Math.floor(aud.length / sampling_rate) * 6;
             const outputs = await this.model.generate({ max_new_tokens, ...kwargs, ...inputs });
 
-            const text = this.processor.batch_decode(outputs, { skip_special_tokens: true })[0];
+            const text = this.processor.batch_decode(/** @type {Tensor} */(outputs), { skip_special_tokens: true })[0];
             toReturn.push({ text });
         }
         return single ? toReturn[0] : toReturn;


Test patch: