Open benediktdertinger opened 4 years ago
Would you mind to send a PR to address this?
Hi @fox1t, I checked your code and found an existing declaration here https://github.com/nualabs/fastify-multer/blob/master/typings/fastify/index.d.ts
Replacing my workaround with your more sophisticated version works perfectly fine for me:
import 'fastify'
import { isMultipart } from '../../src/lib/content-parser'
import { File, FilesObject } from '../../src/interfaces'
type FilesInRequest = FilesObject | Partial<File>[]
declare module 'fastify' {
interface FastifyRequest {
isMultipart: typeof isMultipart
file: File
files: FilesInRequest
}
}
As I'm not very familiar with building fastify plugins: Is this declaration maybe not loaded/initialized correctly?
Very very strange. Can you make a repro repository so we can look further into it? I suppose it is not loaded for some reason.
Hi @fox1t I created this repo for you real quick: https://github.com/nualabs/fastify-multer-ts-files-typings you will find the neccessary steps in the README. I haven't had the time to check everythig in detail so it can also be due to a mistake I made. I'm now off for some days and will reply in mid october. Have a good time :)
One thing I noticed is that types
in package.json
is normally supposed to point at a file but in this case it points at the lib
folder (and the fastify type overrides are outside that folder). I'm guessing it might simply infer the location of the types for the index.js
and resolve the types via imports from there but as the fastify overrides are not imported by anything they have no effect.
🐛 Bug Report
If I use the example
from the README the
request.files
attribute is missing and TS is complainingTS2339: Property 'files' does not exist on type 'FastifyRequest '.
.To Reproduce
Steps to reproduce the behavior:
Expected behavior
request.files
is typed asFile[]
I fixed it extending the fastify module via:
Your Environment