Doesn't throw typescript error.
I get this error after updating the types. I did a re-generate of the whole app.

Module versions (especially the part that's not working):
"@feathersjs/feathers": "^3.3.1",
"@types/feathersjs__feathers": "^3.1.5",
NodeJS version: 10.15
CC @j2L4e @TimMensch any ideas ?
OK, you have two choices when you're creating your app:
interface ServiceTypes {
// I'm not actually sure what type this is intended to be, but boolean works.
authentication: boolean;
}
const app = express(feathers<ServiceTypes>());
app.service("authentication").hooks({}); // works for me
Or
const app = express(feathers()); // default constructor
app.service("authentication").hooks({}); // also works for me
If you create a ServiceTypes object and pass it as the type of the Feathers app, and then you try to reference a service() that isn't a member of ServiceTypes, app.service() will return never, because that's a type error.
I didn't design this, but it's an elegant bit of type declaration.
Hi Tim,
thanks for the quick reply!
I wasn't sure where to put the interface ServiceTypes? In which file and folder?
However adding authentication: true to my type export type App = Application.. in app.interface.ts made it work. Is that fine?
It's a generator generated typescript project.
Do you think this is related to this other issue I have?
See PR https://github.com/feathersjs/feathers/pull/1364 for more details. Essentially, to take advantage of TypeScript checking for mis-spelled services, one could define 'allowed' service names as follows:
type Message = { text: string };
export type Application<{
'messages': Message,
//... other services
}>;
Service names that are not defined will result in the mentioned error. Alternatively, one could provide the typings as:
// All service names allowed, but will be typed as `Service<any>`.
export type Application;
// Explicitly allow any other service names, downside is that any mis-spelled service name won't be caught
export type Application<{
'messages': Message,
[name: string]: any,
}>;
Note in Feathers Crow (v4) app should be typed as follows (see https://github.com/feathersjs/feathers/issues/1369 for details):
export type Application<{
'messages': Service<Message>,
}>;
I think the Feathers team should consider converting the project to TypeScript. Feathers is a great framework but could come short in type safety because type definitions are maintained separate from the source code and so are not always in sync or complete. Have a look at frameworks like NestJS that are written in TypeScript and getting a great start. Also, I suggest avoiding default exports for several reasons (see 1, 2, 3).
I'm going to close this since v4 comes with TypeScript definitions built in and supported in the CLI and docs. See the migration guide for how to upgrade
Most helpful comment
I'm going to close this since v4 comes with TypeScript definitions built in and supported in the CLI and docs. See the migration guide for how to upgrade