Definitelytyped: [[email protected]] why was multer.Instance removed?

Created on 30 Jan 2020  路  4Comments  路  Source: DefinitelyTyped/DefinitelyTyped

The Instance interface was removed and the declare class Multer is not exported.
There is no where to reference the Multer instance.

import multer from 'multer';
const x: multer.Instance = multer();

https://github.com/DefinitelyTyped/DefinitelyTyped/commit/f09d3f850c72391f75cc4c58364c31ee020b6ba0#diff-0b6c549b93259dc4abbf4d6899537232L65-L77

Most helpful comment

If using TypeScript 2.8 or above, you can use the built-in ReturnType helper to extract the return type of from the multer factory function thusly:

import multer from 'multer';

const x: ReturnType<typeof multer> = multer(...);

I would consider this a temporary work-around until something like multer.Instance is re-added to the type defs.

All 4 comments

The Multer class could be probalby just an interface within multer namespace, so that would be corect:

import multer from 'multer';
const x: multer.Multer = multer();

Instance can be aliased to Multer, type Instance = Multer;, for backward compatibility:

import multer from 'multer';
const x: multer.Instance = multer();

sounds OK?

but the Multer class is declared outside multer namespace, and is not exported. so that import { Multer } from 'multer' or simply referencing the class Multer from outside won't work.

Did I miss something? Since if I write

const x: multer.Multer;

or just

import { Multer } from 'multer'
const x: Multer

the compile said cannot find Multer or Multer is not exported.

If using TypeScript 2.8 or above, you can use the built-in ReturnType helper to extract the return type of from the multer factory function thusly:

import multer from 'multer';

const x: ReturnType<typeof multer> = multer(...);

I would consider this a temporary work-around until something like multer.Instance is re-added to the type defs.

The ReturnType trick does not work for me. I'm using TypeScript 3.9. I believe the Multer class declaration needs to change to an exported interface. The odd thing is that multer-tests.ts does not show this problem, even if I change it to export some of the constants that are Multer instances. Exporting the result of a multer() call is what generates an error for me:

Return type of exported function has or is using name 'Multer' from external module "<project_path>/node_modules/@types/multer/index" but cannot be named.ts(4058)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

alisabzevari picture alisabzevari  路  3Comments

Loghorn picture Loghorn  路  3Comments

csharpner picture csharpner  路  3Comments

victor-guoyu picture victor-guoyu  路  3Comments

stevermeister picture stevermeister  路  3Comments