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

README instructions seem to be wrong for TS #171

Open
2 tasks done
georgiosd opened this issue Aug 31, 2023 · 2 comments
Open
2 tasks done

README instructions seem to be wrong for TS #171

georgiosd opened this issue Aug 31, 2023 · 2 comments
Labels
bug Confirmed bug

Comments

@georgiosd
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

Latest

Plugin version

Latest

Node.js version

18

Operating system

Windows

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

11

Description

For TS, the docs say that we just have to augment the fastify interface but I had to do more to get the plugin working without TS errors:

import FastifyEnv from '@fastify/env'
import { JSONSchemaType } from 'env-schema'

<redacted>

type Env = {
  JWT_SECRET: string
}

const envSchema: JSONSchemaType<Env> = {
  type: 'object',
  properties: {
    JWT_SECRET: {
      type: 'string',
    },
  },
  required: ['JWT_SECRET'],
  additionalProperties: false,
}

const app: FastifyPluginAsync<AppOptions> = async (
  fastify,
  opts
): Promise<void> => {
  await fastify.register(FastifyEnv, {
    schema: envSchema,
    dotenv: {
      path: path.join(__dirname, isProduction ? '.env' : '.env.development'),
      debug: isProduction === false,
    },
  })
 
  <redacted>
}

Without all this, either the runtime was complaining about the schema passed to the options, or TS was complaining about the overload used.

Also, there was nothing in the docs about how to copy the .env file to dist/ - I know it's not directly your responsibility but would be nice to add.

Steps to Reproduce

  • Create project with fastify-cli --lang=ts --esm
  • Add code from TS instructions

Expected Behavior

No response

@mcollina
Copy link
Member

mcollina commented Sep 4, 2023

Thanks for reporting! Would you like to send a Pull Request to address this issue? It's likely just a docs issue.

@mcollina mcollina added the bug Confirmed bug label Sep 4, 2023
@georgiosd
Copy link
Author

@mcollina it's on my TODO :)

ardasevinc added a commit to ardasevinc/unsocial that referenced this issue Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bug
Projects
None yet
Development

No branches or pull requests

2 participants