Skip to content

Type error on "files" key when extending "Request" type with @types/express 5.0 #6085

Description

@Bilboramix

Hey, i've got this interface here :

import formidable from "formidable";
import type { Request } from "express";

export interface IRequestWithFiles extends Request {
  files: Record<string, formidable.File>;
}

With the types "@types/express": "^4.17.21" everything is fine
But with "@types/express": "^5.0.0" typescript throws this error :

Conversion of type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>' to type 'IRequestWithFormData' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
  Types of property 'files' are incompatible.
    Type 'Files | undefined' is not comparable to type 'Record<string, File>'.
      Type 'Files' is not comparable to type 'Record<string, File>'.
        'string' index signatures are incompatible.
          Type 'File[] | undefined' is not comparable to type 'File'.
            Type 'File[]' is missing the following properties from type 'File': size, filepath, originalFilename, newFilename, and 3 more.

As a workaround i just renamed the "files" key of my interface.
But i cannot find in the type definition file anything related to the "files" key so i'm wondering why and how this key is typed.
Is there anything coming in future releases that involve that key ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions