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

Property 'config' does not exist on type 'FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault>'. #176

Open
2 tasks done
zoey-t opened this issue Oct 16, 2023 · 1 comment

Comments

@zoey-t
Copy link

zoey-t commented Oct 16, 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.2"

Plugin version

^4.2.0

Node.js version

v18.12.0

Operating system

macOS

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

14.0 (23A344)

Description

The code structure is created with fastify-cli using typescript template.

// file: authorization.ts
import { FastifyInstance } from "fastify"

const authorization = async (fastify:FastifyInstance, opts) => {
	const { httpErrors, config } = fastify // got error: Property 'config' does not exist on type 'FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault>'.
}

Steps to Reproduce

The code structure is created with fastify-cli using typescript template.
maybe the error is cause by @fastify/env not extending the fastify instance object like this

declare module 'fastify' {
  export interface FastifyInstance {
    someSupport(): string;
  }
}

My code

// file: authorization.ts
import { FastifyInstance } from "fastify"

const authorization = async (fastify:FastifyInstance, opts) => {
	const { httpErrors, config } = fastify // got error: Property 'config' does not exist on type 'FastifyInstance<RawServerDefault, IncomingMessage, ServerResponse<IncomingMessage>, FastifyBaseLogger, FastifyTypeProviderDefault>'.
}

I already registerred the "@fastify/env"

// file: app.ts
import Env from "@fastify/env"
const app: FastifyPluginAsync<AppOptions> = async (
	fastify,
	opts
): Promise<void> => {
	// Place here your custom code!
	// env
	void fastify.register(Env, {
		schema: S.object()
			.prop("NODE_ENV", S.string().default("development"))
			.valueOf(),
	})

is it bec

Expected Behavior

No response

@mcollina
Copy link
Member

I think you need to add a TS reference block to load @fastify/env

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

2 participants