Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type error: TypeBoxTypeProvider does not satisfy the constraint FastifyTypeProvider #114

Open
2 tasks done
myftija opened this issue Oct 23, 2023 · 3 comments · May be fixed by #165
Open
2 tasks done

Type error: TypeBoxTypeProvider does not satisfy the constraint FastifyTypeProvider #114

myftija opened this issue Oct 23, 2023 · 3 comments · May be fixed by #165

Comments

@myftija
Copy link

myftija commented Oct 23, 2023

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.24.3

Plugin version

3.5.0

Node.js version

18.15.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

Ventura 13.5.1

Description

TypeBoxTypeProvider produces a type error in version 3.5.0. I am not facing this issue in version 3.1.0.

Steps to Reproduce

import Fastify from 'fastify'
import { TypeBoxTypeProvider } from '@fastify/type-provider-typebox'

const fastify = Fastify().withTypeProvider<TypeBoxTypeProvider>()

This produces a type error:

error TS2344: Type 'TypeBoxTypeProvider' does not satisfy the constraint 'FastifyTypeProvider'.
  Property 'input' is missing in type 'TypeBoxTypeProvider' but required in type 'FastifyTypeProvider'.

Typescript version: 5.0.4

Expected Behavior

No response

@mcollina
Copy link
Member

I cannot reproduce. Can you push your file and tsconfig to a repo?

@paulius-valiunas
Copy link

@mcollina this happens when using pnpm, and probably recent versions of yarn (I haven't tried them but I've heard they're more restrictive than npm). You don't explicitly declare fastify as a dependency or peerDependency, but still import it in index.d.ts, which makes it a phantom dependency. It's all fine if the consumer is using npm, because npm allows phantom dependencies. But if they use pnpm, when you try to import FastifyTypeProvider from fastify, you get an unknown type because fastify is not declared as a dependency and thus not accessible from your modules:
image
image

Workaround:

Adding this to my package.json fixed the issue for me:

"pnpm": {
  "packageExtensions": {
    "@fastify/type-provider-typebox@^3.6.0": {
      "peerDependencies": {
        "fastify": "^4.16.0"
      }
    }
  }
}

Needless to say, I think it should be permanently fixed by adding the peerDependency to your package.

@paulius-valiunas paulius-valiunas linked a pull request Aug 13, 2024 that will close this issue
@markandrus
Copy link

The same issue occurs in recent versions of Yarn. I discovered this while updating to 5.x. The problem can be worked around by adding the following to .yarnrc.yml in a Yarn project's root:

packageExtensions:
  "@fastify/type-provider-typebox@5.x":
    peerDependencies:
      "fastify": "5.x"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants