Skip to content
On this page

Pre-release

You are looking at the website for the fully functional Feathers v5 (Dove) pre-release. Check out what's new, and please let us know about any issues or questions . The current v4 documentation can be found at crow.docs.feathersjs.com.

TypeScript

The main file for application specific TypeScript declarations can be found at src/declarations.ts.

Compilation

In order to compile and start the application use

npm run compile
npm start
npm run compile
npm start

For development with live reload use

npm run dev
npm run dev

Important

To get the latest types in the client and any time before npm start, npm run compile needs to run.

Configuration Types

The Configuration interface defines the types for app.get and app.set. It is extended from the type inferred from the configuration schema. Since you can store anything global to the application in app.get and app.set, you can add additional types that are not part of the initial application configuration here.

ts
// The types for app.get(name) and app.set(name)
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface Configuration extends ApplicationConfiguration {
  startupTime: Date
}
// The types for app.get(name) and app.set(name)
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface Configuration extends ApplicationConfiguration {
  startupTime: Date
}
export {}
export {}

Important

Both Configuration and ServiceTypes need to be declared as an interface (even if it is empty) so they can be extended via declare module in other files. Do not remove the eslint-disable-next-line comments.

Service Types

The ServiceTypes interface contains a mapping of all service paths to their service type so that app.use and app.service use the correct type.

ts
// A mapping of service names to types. Will be extended in service files.
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ServiceTypes {}
// A mapping of service names to types. Will be extended in service files.
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface ServiceTypes {}
export {}
export {}

Usually the ServiceTypes interface is not modified directly in this file but instead extended via declare module in the files where the services are registered. This usually looks like this:

ts
// Add this service to the service type index
declare module '../../declarations' {
  interface ServiceTypes {
    users: UserService
  }
}
// Add this service to the service type index
declare module '../../declarations' {
  interface ServiceTypes {
    users: UserService
  }
}

Application

The Application interface is the type for the main app object using the ServiceTypes interface as the service index and ConfigurationTypes for app.get and app.set.

ts
// The application instance type that will be used everywhere else
export type Application = FeathersApplication<ServiceTypes, Configuration>
// The application instance type that will be used everywhere else
export type Application = FeathersApplication<ServiceTypes, Configuration>
export {}
export {}

Important

Always use import { Application } from './declarations' to get the proper service and configuration typings. You normally do not need to use import { Application } from '@feathersjs/feathers' directly.

Hook Context

The HookContext type exports a hook context type with the Application and a generic service type S.

ts
// The context for hook functions - can be typed with a service class
export type HookContext<S = any> = FeathersHookContext<Application, S>
// The context for hook functions - can be typed with a service class
export type HookContext<S = any> = FeathersHookContext<Application, S>
export {}
export {}

Use HookContext<FeathersService<UserService>> to get the full hook context for a service.

Services and Params

See the services chapter for more information on service and parameter typings.

Released under the MIT License.