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

Typescript: ListOption for format: 'json' is invalid #222

Closed
2 tasks done
lordnox opened this issue Jul 14, 2021 · 3 comments · Fixed by #304
Closed
2 tasks done

Typescript: ListOption for format: 'json' is invalid #222

lordnox opened this issue Jul 14, 2021 · 3 comments · Fixed by #304
Labels

Comments

@lordnox
Copy link

lordnox commented Jul 14, 2021

Prerequisites

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

Fastify version

3.19.1

Plugin version

4.2.2

Node.js version

14.17.1

Operating system

macOS

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

11.4 (Apple M1 Chip)

Description

The type for list (boolean | ListOptions) is not correct for the json case:

interface ListOptions {
  format: 'json' | 'html';
  names: string[];
  render: ListRender;
}

It should not include the render property as it is not used in json but required here

Steps to Reproduce

  const staticOptions: FastifyStaticOptions = {
    root: path.resolve(options.imagePath),
    prefix: options.path,
    dotfiles: 'ignore',
    prefixAvoidTrailingSlash: true,
    list: {
      format: 'json',
      names: ['index', 'index.json', '/', ''],
     // missing render 
    },
  }

Expected Behavior

type ListOptions {
  format: 'json';
  names: string[];
} | {
  format: 'html';
  names: string[];
  render: ListRender;
}
@Eomm
Copy link
Member

Eomm commented Jul 14, 2021

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

@stale
Copy link

stale bot commented Apr 16, 2022

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.

@stale stale bot added the stale label Apr 16, 2022
@stale stale bot closed this as completed Apr 28, 2022
@is2ei
Copy link
Contributor

is2ei commented May 18, 2022

This issue is still a problem.
e.g. https://stackblitz.com/edit/node-yonvhw?file=index.ts

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

Successfully merging a pull request may close this issue.

3 participants