Giter VIP home page Giter VIP logo

Comments (14)

QEDK avatar QEDK commented on August 11, 2024 4

@ziimakc I think the issue still exists:

index.ts(6,7): error TS2322: Type 'FastifyInstance<Http2SecureServer, Http2ServerRequest, Http2ServerResponse, FastifyBaseLogger, FastifyTypeProviderDefault> & PromiseLike<...>' is not assignable to type 'FastifyInstance<Server, IncomingMessage, ServerResponse, FastifyBaseLogger, FastifyTypeProviderDefault>'.
  Types of property 'server' are incompatible.
    Type 'Http2SecureServer' is missing the following properties from type 'Server': maxHeadersCount, maxRequestsPerSocket, timeout, headersTimeout, and 4 more.

from fastify-static.

evanshortiss avatar evanshortiss commented on August 11, 2024 1

Gotcha, looks like following the plugin structure style from those other packages will help! Nice work on the PR, I see Ethan is reviewing so it'll be all good 👍

from fastify-static.

mcollina avatar mcollina commented on August 11, 2024 1

please open a fresh issue with a reproduction

from fastify-static.

mcollina avatar mcollina commented on August 11, 2024

no reason. Making really dynamic code with typescript is hard. PRs are welcome!

from fastify-static.

ziimakc avatar ziimakc commented on August 11, 2024

I'm new to typescript, so i will pass it for now to anyone who is more knowledgeable of typescript generics and declaration files, as i don't see a clear way to make it work for different interfaces.

Temporally i changed index.d.ts of fastify-static to:

import { Http2SecureServer, Http2ServerRequest, Http2ServerResponse } from "http2"
declare const fastifyStatic: fastify.Plugin<Http2SecureServer, Http2ServerRequest, Http2ServerResponse, {//options }>;

Upd:
You can also use // @ts-ignore comment before registering module to solve it

from fastify-static.

evanshortiss avatar evanshortiss commented on August 11, 2024

@ReTWi, do you have a more complete example? What's your tsconfig, what other code is in your file?

The following code compiles and runs if I use npx tsc index.ts --target es6 --module commonjs:

import * as fastify from 'fastify'
import { resolve } from 'path'
import { Http2SecureServer, Http2ServerRequest, Http2ServerResponse } from 'http2'

const https: fastify.FastifyInstance<Http2SecureServer, Http2ServerRequest, Http2ServerResponse> = fastify({
    logger: true,
    ignoreTrailingSlash: true,
    http2: true,
    https: { allowHTTP1: true }
})

https.register(require('fastify-static'), {
    root: resolve(__dirname, 'public',),
    prefix: '/public/', // optional: default '/'
})

https.listen(8080)

from fastify-static.

ziimakc avatar ziimakc commented on August 11, 2024

@evanshortiss i will make a PR in a few minutes to fix this.

My code runs and works too, but there is always a warning from typescript.
I don't think you need something more to get a warning.

Config is:

{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node",
    "esModuleInterop": true,
    "sourceMap": true,
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "removeComments": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "strictBindCallApply": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "allowJs": true,
    "strictPropertyInitialization": true
  },
  "exclude": [
    "../../node_modules"
  ]
}

 "target": "es2019"

from fastify-static.

ziimakc avatar ziimakc commented on August 11, 2024

@evanshortiss i found that i have no warning if i use
require('fastify-static')
instead of
import fastifyStatic from 'fastify-static'

from fastify-static.

evanshortiss avatar evanshortiss commented on August 11, 2024

@ReTWi you included a compiler error, not warning in the original issue though. Have I misunderstood? A compiler error means the code doesn't compile and therefore does not run.

from fastify-static.

ziimakc avatar ziimakc commented on August 11, 2024

@evanshortiss it's error, but it's compiles and works so i sad "warning". Sorry if i misguided you

from fastify-static.

stale avatar stale commented on August 11, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from fastify-static.

SahasSaurav avatar SahasSaurav commented on August 11, 2024

Capture

No overload matches this call.
The last overload gave the following error.
Argument of type '{ logger: { level: string; transport: { target: string; }; serializers: { res(reply: FastifyReply<Server, IncomingMessage, ServerResponse, RouteGenericInterface, unknown, FastifySchema, FastifyTypeProviderDefault, unknown>): { ...; }; req(request: FastifyRequest<...>): { ...; }; }; }; bodyLimit: number; requestTimeo...' is not assignable to parameter of type 'FastifyServerOptions<Server, FastifyBaseLogger>'.
Object literal may only specify known properties, and 'http2' does not exist in type 'FastifyServerOptions<Server, FastifyBaseLogger>'.ts(2769)
fastify.d.ts(56, 18): The last overload is declared here.

from fastify-static.

Dhruv-Garg79 avatar Dhruv-Garg79 commented on August 11, 2024

The issue is still there

from fastify-static.

Dhruv-Garg79 avatar Dhruv-Garg79 commented on August 11, 2024

this issue should be re-opened @mcollina?

from fastify-static.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.