Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

79
Views
Burlarse de la firma de sobrecarga de función específica

Tengo el siguiente código

 import { readdir } from 'fs/promises'; const files: string[] = await readdir('/original/file/path');

que estoy tratando de probar

 import * as fsPromisesModule from "fs/promises"; stub(fsPromisesModule, "readdir").callsFake(async (): Promise<string[]> => ['/test/file/path']);

pero me sale el siguiente error

 Type 'Promise<string[]>' is not assignable to type 'Promise<Dirent[]>'. Type 'string[]' is not assignable to type 'Dirent[]'. Type 'string' is not assignable to type 'Dirent'.ts(2322)

El archivo promises.d.ts contiene las siguientes firmas

 function readdir( path: PathLike, options?: | (ObjectEncodingOptions & { withFileTypes?: false | undefined; }) | BufferEncoding | null ): Promise<string[]>; function readdir( path: PathLike, options: | { encoding: 'buffer'; withFileTypes?: false | undefined; } | 'buffer' ): Promise<Buffer[]>; function readdir( path: PathLike, options?: | (ObjectEncodingOptions & { withFileTypes?: false | undefined; }) | BufferEncoding | null ): Promise<string[] | Buffer[]>; function readdir( path: PathLike, options: ObjectEncodingOptions & { withFileTypes: true; } ): Promise<Dirent[]>;

La última firma se usa en el código auxiliar, pero quiero usar la primera firma. ¿Cómo puedo decirle a TypeScript que es la firma que quiero usar en mis pruebas?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Según la respuesta vinculada a @andreyunugros, lo siguiente funcionó;

 (stub(fsPromisesModule, "readdir") as unknown as SinonStub<[p: PathLike], Promise<string[]>>).callsFake(async (): Promise<string[]> => (['/file/path/name']);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!