@types/[email protected] package and had no problems.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
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)
Most helpful comment
If using TypeScript 2.8 or above, you can use the built-in
ReturnTypehelper to extract the return type of from the multer factory function thusly:I would consider this a temporary work-around until something like
multer.Instanceis re-added to the type defs.