Skip to content

Different types of Application from @feathersjs/feathers and @feathersjs/express (dove) #2533

@idaho

Description

@idaho

Steps to reproduce

During the usage of the Application, we get some incompatibility between the types of @feathersjs/feathers and @feathersjs/express.

  1. Getting incorrect settings types if we are using the Application of @feathersjs/express, but with @feathersjs/feathers we get.
import * as express from '@feathersjs/express';
import { feathers } from '@feathersjs/feathers';

interface Configuration {
  foo: boolean;
  bar: string;
}

type Application = express.Application<any, { configuration: Configuration }>;

const configuration: Configuration = {
  foo: true,
  bar: 'baz'
};

const expressify = express.default;

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

application.set('configuration', configuration);

const { foo } = application.get('configuration')

no-setting-types

import * as express from '@feathersjs/express';
import { feathers , Application as FeathersApplication } from '@feathersjs/feathers';

interface Configuration {
  foo: boolean;
  bar: string;
}

type Application = FeathersApplication<any, { configuration: Configuration }>;

const configuration: Configuration = {
  foo: true,
  bar: 'baz'
};

const expressify = express.default;

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

application.set('configuration', configuration);

const { foo } = application.get('configuration')

settings-type

  1. cannot use express middleware with Application type of @feathersjs/feathers
import * as express from '@feathersjs/express';
import { feathers , Application as FeathersApplication } from '@feathersjs/feathers';
import { NextFunction, Request, Response } from 'express-serve-static-core';
import { IncomingMessage, ServerResponse } from 'http';

type Application = FeathersApplication<any, any>;

const expressify = express.default;

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

application.use(`*/_next`, async (req: Request, res: Response, next: NextFunction): Promise<void> => {
   next();
});

application.all('*', async (req: IncomingMessage, res: ServerResponse, next: NextFunction): Promise<void> => {
  next();
});

Getting error:

  • Type '(req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>, number>, next: NextFunction) => Promise<...>' has no properties in common with type 'Partial<ServiceMethods<any, Partial>>
  • Property 'all' does not exist on type 'Application'.ts(2339)

But if we are using the @feathers/express Application type, it works, but then the settings types of the Application aren't available any more.

Expected behavior

In the @feathersjs/feathers Application type, it should be possible to add a custom express middleware if we are using express. Even the all method should be available, because of the different behaviour to use.

System configuration

Module versions (especially the part that's not working):

@feathersjs/express: 5.0.0-pre.15
@feathersjs/feathers: 5.0.0-pre.15
typescript: 4.5.4

NodeJS version:
16.13.3

Operating System:

macOS: 10.15.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions