chanphiromsok / fastify-file-interceptor

fastify file interceptor is create for upload image for NestJs using FastifyAdapter
MIT License
22 stars 3 forks source link

nest 10 support #5

Closed shahirsoft closed 10 months ago

shahirsoft commented 1 year ago

after update to nest ver 10 I'm getting an error message

error TS2345: Argument of type 'FastifyPluginCallback<PluginOptions, Server<typeof IncomingMessage, typeof ServerResponse>, FastifyTypeProviderDefault, FastifyBaseLogger>' is not assignable to parameter of type 'FastifyPluginCallback | FastifyPluginAsync | Promise<{ default: FastifyPluginCallback; }> | Promise<...>'. Type 'FastifyPluginCallback<PluginOptions, Server<typeof IncomingMessage, typeof ServerResponse>, FastifyTypeProviderDefault, FastifyBaseLogger>' is not assignable to type 'FastifyPluginCallback'. Types of parameters 'instance' and 'instance' are incompatible. Type 'FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse, FastifyBaseLogger, FastifyTypeProviderDefault>' is missing the following properties from type 'FastifyInstance<Server<typeof IncomingMessage, typeof ServerResponse>, IncomingMessage, ServerResponse, FastifyBaseLogger, FastifyTypeProviderDefault>': websocketServer, graphql, graphqlGateway, rateLimit

97 await app.register(contentParser);

chanphiromsok commented 11 months ago

Thanks for report the issue I fixed as soon as possible

chanphiromsok commented 10 months ago

Not relate to package ,Hi please check your nestjs cli version I think in your main.ts has issue like this one make sure ur nestjs/cli is up to date https://github.com/nestjs/nest/issues/4036

newradius commented 7 months ago

Tried with nest 10.3.1 but I get some incopatibilty errors:

node_modules/fastify-multer/node_modules/fastify-plugin/plugin.d.ts:16:60 - error TS2344: Type 'Options' does not satisfy the constraint 'FastifyPluginOptions'.

16 export default function fp<Options>(fn: FastifyPluginAsync<Options>, options?: PluginMetadata): FastifyPluginAsync<Options>;                                 
                                                              ~~~~~~~                                                                                           

  node_modules/fastify-multer/node_modules/fastify-plugin/plugin.d.ts:16:28                                                                                     
    16 export default function fp<Options>(fn: FastifyPluginAsync<Options>, options?: PluginMetadata): FastifyPluginAsync<Options>;                             
                                  ~~~~~~~                                                                                                                       
    This type parameter might need an `extends FastifyPluginOptions` constraint.                                                                                

node_modules/fastify-multer/node_modules/fastify-plugin/plugin.d.ts:16:116 - error TS2344: Type 'Options' does not satisfy the constraint 'FastifyPluginOptions'.

16 export default function fp<Options>(fn: FastifyPluginAsync<Options>, options?: PluginMetadata): FastifyPluginAsync<Options>;                                  
                                                                                                                      ~~~~~~~                                    

  node_modules/fastify-multer/node_modules/fastify-plugin/plugin.d.ts:16:28
    16 export default function fp<Options>(fn: FastifyPluginAsync<Options>, options?: PluginMetadata): FastifyPluginAsync<Options>;
                                  ~~~~~~~
    This type parameter might need an `extends FastifyPluginOptions` constraint.

node_modules/fastify-multer/node_modules/fastify-plugin/plugin.d.ts:17:60 - error TS2344: Type 'Options' does not satisfy the constraint 'FastifyPluginOptions'.

17 export default function fp<Options>(fn: FastifyPluginAsync<Options>, options?: string): FastifyPluginAsync<Options>;
                                                              ~~~~~~~

  node_modules/fastify-multer/node_modules/fastify-plugin/plugin.d.ts:17:28
    17 export default function fp<Options>(fn: FastifyPluginAsync<Options>, options?: string): FastifyPluginAsync<Options>;
                                  ~~~~~~~
    This type parameter might need an `extends FastifyPluginOptions` constraint.

node_modules/fastify-multer/node_modules/fastify-plugin/plugin.d.ts:17:108 - error TS2344: Type 'Options' does not satisfy the constraint 'FastifyPluginOptions'.

17 export default function fp<Options>(fn: FastifyPluginAsync<Options>, options?: string): FastifyPluginAsync<Options>;
                                                                                                              ~~~~~~~

  node_modules/fastify-multer/node_modules/fastify-plugin/plugin.d.ts:17:28
    17 export default function fp<Options>(fn: FastifyPluginAsync<Options>, options?: string): FastifyPluginAsync<Options>;
                                  ~~~~~~~
    This type parameter might need an `extends FastifyPluginOptions` constraint.

node_modules/fastify-multer/node_modules/fastify-plugin/plugin.d.ts:18:63 - error TS2344: Type 'Options' does not satisfy the constraint 'FastifyPluginOptions'.

    19 export default function fp<Options>(fn: FastifyPluginCallback<Options>, options?: string): FastifyPluginCallback<Options>;
                                  ~~~~~~~
    This type parameter might need an `extends FastifyPluginOptions` constraint.

node_modules/fastify-multer/node_modules/fastify-plugin/plugin.d.ts:19:114 - error TS2344: Type 'Options' does not satisfy the constraint 'FastifyPluginOptions'.

19 export default function fp<Options>(fn: FastifyPluginCallback<Options>, options?: string): FastifyPluginCallback<Options>;
                                                                                                                    ~~~~~~~

  node_modules/fastify-multer/node_modules/fastify-plugin/plugin.d.ts:19:28
    19 export default function fp<Options>(fn: FastifyPluginCallback<Options>, options?: string): FastifyPluginCallback<Options>;
                                  ~~~~~~~
    This type parameter might need an `extends FastifyPluginOptions` constraint.

I already checked the post you linked but my deps match:

"dependencies": {
    "@fastify/helmet": "11.1.1",
    "@fastify/multipart": "8.1.0",
    "@fastify/static": "6.12.0",
    "@nestjs-modules/mailer": "1.10.3",
    "@nestjs/common": "10.3.1",
    "@nestjs/config": "3.1.1",
    "@nestjs/core": "10.3.1",
    "@nestjs/jwt": "10.2.0",
    "@nestjs/passport": "10.0.3",
    "@nestjs/platform-fastify": "10.3.1",
    "@nestjs/schedule": "^4.0.0",
    "@nestjs/serve-static": "4.0.0",
    "@nestjs/swagger": "7.2.0",
    "@nestjs/typeorm": "10.0.1",
    "bcryptjs": "2.4.3",
    "fastify": "4.26.0",
    "fastify-file-interceptor": "1.0.9",
    "glob": "10.3.10",
    "handlebars": "4.7.8",
    "mime-types": "2.1.35",
    "moment": "^2.30.1",
    "multer": "1.4.4",
    "mysql": "2.18.1",
    "nodemailer": "6.9.8",
    "passport": "0.7.0",
    "passport-jwt": "4.0.1",
    "passport-local": "1.0.0",
    "reflect-metadata": "0.2.1",
    "rimraf": "5.0.5",
    "rxjs": "7.8.1",
    "typeorm": "0.3.20",
    "ulid": "2.3.0"
  },
  "devDependencies": {
    "@commitlint/cli": "18.6.0",
    "@commitlint/config-conventional": "18.6.0",
    "@cucumber/cucumber": "10.3.1",
    "@cucumber/pretty-formatter": "1.0.0",
    "@nestjs/cli": "10.3.0",
    "@nestjs/schematics": "10.1.0",
    "@nestjs/testing": "10.3.1",
    "@types/bcryptjs": "2.4.6",
    "@types/cors": "2.8.17",
    "@types/glob": "8.1.0",
    "@types/inline-css": "3.0.3",
    "@types/jest": "29.5.11",
    "@types/multer": "1.4.11",
    "@types/node": "20.11.10",
    "@types/nodemailer": "6.4.14",
    "@types/passport-jwt": "4.0.1",
    "@types/supertest": "6.0.2",
    "@types/uuid": "9.0.8",
    "@typescript-eslint/eslint-plugin": "6.20.0",
    "@typescript-eslint/parser": "6.20.0",
    "eslint": "8.56.0",
    "eslint-config-airbnb-typescript": "17.1.0",
    "eslint-config-prettier": "9.1.0",
    "eslint-import-resolver-typescript": "3.6.1",
    "eslint-plugin-import": "2.29.1",
    "eslint-plugin-prettier": "5.1.3",
    "expect": "29.7.0",
    "husky": "9.0.7",
    "jest": "29.7.0",
    "jsonlint": "1.6.3",
    "lint-staged": "15.2.0",
    "nyc": "15.1.0",
    "prettier": "3.2.4",
    "supertest": "6.3.4",
    "ts-jest": "29.1.2",
    "ts-loader": "9.5.1",
    "ts-node": "10.9.2",
    "tsconfig-paths": "4.2.0",
    "typescript": "5.3.3"
  }
newradius commented 7 months ago

I changed the signature of the methods like the error suggests and it works:

export default function fp<Options extends FastifyPluginOptions>(fn: FastifyPluginAsync<Options>, options?: PluginMetadata): FastifyPluginAsync<Options>;
export default function fp<Options extends FastifyPluginOptions>(fn: FastifyPluginAsync<Options>, options?: string): FastifyPluginAsync<Options>;
export default function fp<Options extends FastifyPluginOptions>(fn: FastifyPluginCallback<Options>, options?: PluginMetadata): FastifyPluginCallback<Options>;
export default function fp<Options extends FastifyPluginOptions>(fn: FastifyPluginCallback<Options>, options?: string): FastifyPluginCallback<Options>;
chanphiromsok commented 6 months ago

do you have reproduce repo ?