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

Missing set and get types for default express application properties #2562

Open
idaho opened this issue Feb 17, 2022 · 1 comment
Open

Missing set and get types for default express application properties #2562

idaho opened this issue Feb 17, 2022 · 1 comment

Comments

@idaho
Copy link
Contributor

idaho commented Feb 17, 2022

Steps to reproduce

With the new pre-release version of dove (5.0.0-pre.17) and the use of Typescript, we can no longer set etag, query parser etc. in an Express application after we have defined the settings generic, during the definition of the application.

Example

import { Application as eApplication } from '@feathersjs/express';
import { feathers } from '@feathersjs/feathers';
import qs from 'qs';
import * as express from '@feathersjs/express';

interface ApplicationSettings {
  port: number;
  host: string;
};

type Application = eApplication<{}, { configuration: ApplicationSettings }>;

const expressify = express.default;

const application: Application = expressify(feathers());

application.set('configuration', {
  port: 3040,
  host: 'localhost'
});


application.set('etag', false);
application.disable('etag');
application.disable('x-powered-by');

application.set('query parser', (str: string) => qs.stringify(str));

We now get the following errors:

  • Argument of type "etag" is not assignable to parameter of type "configuration".
  • Argument of type "query parser" is not assignable to parameter of type "configuration".

Expected behaviour

We don't get any error when we set those properties.

Actual behaviour

Build will fail if we don't extend the setting generic with Record<string, any>. All other approaches like using won't fix this.

type Application = eApplication<{}, any & { configuration: ApplicationSettings }>;

If we extend with any, we have the same behaviour as before this release. That means we get for configuration the type any.

System configuration

feathersjs: all packages 5.0.0-pre.17

NodeJS version: 16.3.2

Operating System: MacOS 12.2.1

Module Loader: typescript / commonjs

@daffl
Copy link
Member

daffl commented Feb 17, 2022

The most straightforward approach I'm seeing would be to update the configuration type with the settings that are being use. So here something like:

type AppConfig = {
  configuration: ApplicationSettings,
  etag: boolean,
  'x-powered-by': boolean
}

type Application = eApplication<{}, AppConfig>;

I wonder if there is a way to add the Express settings listed here in by default.

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