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

Tags property doesn't exist in FastifySchema in TypeScript #664

Closed
2 tasks done
marko1010 opened this issue Sep 9, 2022 · 6 comments
Closed
2 tasks done

Tags property doesn't exist in FastifySchema in TypeScript #664

marko1010 opened this issue Sep 9, 2022 · 6 comments

Comments

@marko1010
Copy link

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.5.3

Plugin version

7.5.1

Node.js version

14.7.3

Operating system

Windows

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

10

Description

When trying to add 'tags' property to Fastify schema, TypeScript complains with the following error:

Type '{ tags: string[]; body: TObject<{ firstName: TOptional<TString>; lastName: TOptional<TString>; email: TString; password: TString; }>; }' is not assignable to type 'FastifySchema'.
  Object literal may only specify known properties, and 'tags' does not exist in type 'FastifySchema'.ts(2322)

Steps to Reproduce

 fastify.post<{ Body: newUserType }>('/register', { schema: { tags: ['user'], body: newUserSchema } }, async (req, rep) => {
  });

Expected Behavior

No response

@mcollina
Copy link
Member

mcollina commented Sep 9, 2022

cc @fastify/typescript

@oitozero
Copy link

@marko1010 I'm having the same problem. Have you been able to solve it? cc/ @mcollina

@CNLHC
Copy link

CNLHC commented Oct 29, 2022

@marko1010 I'm having the same problem. Have you been able to solve it? cc/ @mcollina

@oitozero A quick fix: creating a global index.d.ts and using type augmentation

declare module 'fastify' {
    interface FastifySchema {
        body?: unknown;
        querystring?: unknown;
        params?: unknown;
        headers?: unknown;
        response?: unknown;
        tags?: string[]
    }
}

This can fix the problem but is not a good solution.

I think we need to wait for the developer to add the missing type to the type definition.

@climba03003
Copy link
Member

I think we need to wait for the developer to add the missing type to the type definition.

The types exist, most of the issue related to project setup.
And I didn't see a repro for us to debug.

@CNLHC
Copy link

CNLHC commented Oct 30, 2022

I think we need to wait for the developer to add the missing type to the type definition.

The types exist, and most of the issues are related to project setup. And I didn't see a repro for us to debug.

oh you are right, the type can be found at

interface FastifySchema {

So the cause of this PR is the extra type shipped with this package is not recognized by the typescript. It does sound like a project setup problem.

@Kislax
Copy link

Kislax commented May 10, 2023

@marko1010, @oitozero
Hello, I spent about 5 hours to find what the problem was, it turned out that I did not import the plugins correctly
As you wrote, it depends on the configuration of ts, namely the selected type of module/moduleResolution

Hope it helps someone

Source link
fastify/fastify#4122

not working
image

worked.
image

need import library to file

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

No branches or pull requests

6 participants