Feathers Typescript
Opened this issue · 2 comments
Hi @idaho
Used the CLI to build a TypeScript FeatherJs app.
I can't get feathers-async-boot to work with it!
I tried import but that gives a myriad of errors, but also requiring the module gives errors.
Would you mind having a look and seeing how I can get this to work with the TypeScript version?
Hi @EmileSpecs can you post the error you got and code example .
Hi @idaho
Using the project generated by the Feathers CLI (choosing TypeScript) and simply adding this to app.ts
.
import boot from 'feathers-async-boot';
app.configure(boot);
app.bootstrap([objection]);
The objection config file's function looks as follows:
import { Model } from 'objection';
import knex from 'knex';
import { Application } from './declarations';
export default async function (app: Application): Promise<any> {
const { client, connection } = app.get('postgres');
const db = knex({ client, connection, useNullAsDefault: false });
await db.raw('CREATE EXTENSION IF NOT EXISTS pgcrypto');
Model.knex(db);
app.set('knex', db);
}
boot
gives this error:
Argument of type 'typeof import("/node_modules/feathers-async-boot/index")' is not assignable to parameter of type '(this: Application<ServiceTypes>, app: Application<ServiceTypes>) => void'. Type 'typeof import("/node_modules/feathers-async-boot/index")' provides no match for the signature '(this: Application<ServiceTypes>, app: Application<ServiceTypes>): void'.ts(2345)
app.bootstrap([objection]);
gives this error:
No overload matches this call. Overload 1 of 2, '(addModulesToBoot: BootModule[]): void', gave the following error. Type '(app: Application<ServiceTypes>) => Promise<any>' is not assignable to type 'BootModule'. Types of parameters 'app' and 'app' are incompatible. Type 'Application<{}> | undefined' is not assignable to type 'Application<ServiceTypes>'. Type 'undefined' is not assignable to type 'Application<ServiceTypes>'. Type 'undefined' is not assignable to type 'Express'. Overload 2 of 2, '(addModuleToBoot: BootModule): void', gave the following error. Argument of type '((app: Application<ServiceTypes>) => Promise<any>)[]' is not assignable to parameter of type 'BootModule'. Type '((app: Application<ServiceTypes>) => Promise<any>)[]' provides no match for the signature '(app?: Application<{}> | undefined): Promise<any>'.ts(2769)
I'm new to TypeScript so I'm not quite sure how to resolve this. To me one problem seems that the Application
type definition differs.
feathers-async-boot
uses the Application
type "as is" as in index.d.ts:
import { Application } from '@feathersjs/feathers';
Feathers defines it like this in declarations.d.ts:
import { Application as ExpressFeathers } from '@feathersjs/express';
// A mapping of service names to types. Will be extended in service files.
export interface ServiceTypes {}
// The application instance type that will be used everywhere else
export type Application = ExpressFeathers<ServiceTypes>;
If this is the core issue, should feathers-async-boot
not use the Application
as defined by Feathers app somehow?