(Had to make a couple of changes in the imports to make it work with my config.
[ERROR] 23:35:52 ⨯ Unable to compile TypeScript:
src/app.ts:47:9 - error TS2769: No overload matches this call.
The last overload gave the following error.
Argument of type 'string' is not assignable to parameter of type 'RequestHandler
47 app.use('/', _static(app.get('public')));
import path from 'path';
import favicon from 'serve-favicon';
import compress from 'compression';
import helmet from 'helmet';
import cors from 'cors';
import { feathers } from '@feathersjs/feathers';
import configuration from '@feathersjs/configuration';
import {
default as express,
json,
urlencoded,
rest,
static as _static,
notFound,
errorHandler
} from '@feathersjs/express';
import socketio from '@feathersjs/socketio';
import { Application } from './declarations';
import logger from './logger';
import middleware from './middleware';
import services from './services';
import appHooks from './app.hooks';
import channels from './channels';
import { HookContext as FeathersHookContext } from '@feathersjs/feathers';
import authentication from './authentication';
import mongoose from './mongoose';
// Don't remove this comment. It's needed to format import lines nicely.
const app: Application = express(feathers());
export type HookContext<T = any> = { app: Application } & FeathersHookContext<T>;
// Load app configuration
app.configure(configuration());
// Enable security, CORS, compression, favicon and body parsing
app.use(helmet({
contentSecurityPolicy: false
}));
app.use(cors());
app.use(compress());
app.use(json());
app.use(urlencoded({ extended: true }));
app.use(favicon(path.join(app.get('public'), 'favicon.ico')));
// Host the public folder
app.use('/', _static(app.get('public')));
// Set up Plugins and providers
app.configure(rest());
app.configure(socketio());
app.configure(mongoose);
// Configure other middleware (see `middleware/index.ts`)
app.configure(middleware);
app.configure(authentication);
// Set up our services (see `services/index.ts`)
app.configure(services);
// Set up event channels (see channels.ts)
app.configure(channels);
// Configure a middleware for 404s and the error handler
app.use(notFound());
app.use(errorHandler({ logger } as any));
app.hooks(appHooks);
export default app;
For my services had to do something like this, but not sure if it should be this way:
// Initializes the `users` service on path `/users`
import { ServiceAddons } from '@feathersjs/feathers';
import { Application } from '../../declarations';
import { Users } from './users.class';
import createModel from '../../models/users.model';
import hooks from './users.hooks';
// Add this service to the service type index
declare module '../../declarations' {
interface ServiceTypes {
'users': Users | ServiceAddons<any, Users>;
}
}
export default function (app: Application): void {
const options = {
Model: createModel(app),
paginate: app.get('paginate')
};
// Initialize our service with any options it requires
app.use<'users'>('users', new Users(options, app));
// Get our initialized service so that we can register hooks
const service = app.service('/users' as 'users');
service.hooks(hooks);
}
I have a feeling I tested against the wrong version as you pointed out in #2289 so I'll definitely need to have another look and start writing up a TypeScript usage and migration page (e.g. one good thing is that service types no longer need the | ServiceAddons<any>).
Thank you for trying the prerelease out and reporting things back!
What is the first type parameter to ServiceAddons for? I'm on 5.0.0-pre2 and it looks like it's not being used at all 🤔
What is the first type parameter to
ServiceAddonsfor? I'm on 5.0.0-pre2 and it looks like it's not being used at all 🤔
Based on what I found in the type definitions, it's <Application, Service>
I probably should add defaults for it then. With the new declarations it doesn't need to be added explicitly anymore though:
declare module '../../declarations' {
interface ServiceTypes {
'users': Users;
}
}
Should work and
const service = app.service('users');
service.on('created', console.log);
Will have all the additional methods.
This should be fixed now in v5.0.0-pre.3
Thanks @daffl , do you have an update plan for the feathers-cli package for v5?
Not really, there's is still _a lot_ of work needed for a proper update as outlined in https://github.com/feathersjs/cli/issues/253
However, all changes necessary are outlined in the migration guide and everything else should continue to work as is.
Here is a diff for the migration steps required for the feathers-chat: https://github.com/feathersjs/feathers-chat/compare/dove-pre?expand=1
Most helpful comment
Not really, there's is still _a lot_ of work needed for a proper update as outlined in https://github.com/feathersjs/cli/issues/253
However, all changes necessary are outlined in the migration guide and everything else should continue to work as is.
Here is a diff for the migration steps required for the feathers-chat: https://github.com/feathersjs/feathers-chat/compare/dove-pre?expand=1