Can't compile Typescript
Navino16 opened this issue · comments
Hello, I can't run any featherjs project in Typescript
Steps to reproduce
- Create new directory, for exemple directory named "test"
- Run feathers-plus generate options
- Run feathers-plus generate app
- Run npm run tslint
- Run npm run compile
Expected behavior
Successfull compile without any error.
Actual behavior
Compile crash :
src/app.ts(76,15): error TS2345: Argument of type '(app: Application<{}>) => void' is not assignable to parameter of type '(this: Application<any>, app: Application<any>) => void'. Types of parameters 'app' and 'app' are incompatible. Type 'Application<any>' is missing the following properties from type 'Application<{}>': search, connect, init, defaultConfiguration, and 39 more.
Note that adding a service generate (with default options) this error:
src/services/index.ts(11,17): error TS2345: Argument of type '(app: Application<{ 'messages': Message; }>) => void' is not assignable to parameter of type '(this: Application<{ 'messages': Message; }>, app: Application<{ 'messages': Message; }>) => void'. Types of parameters 'app' and 'app' are incompatible. Type 'Application<{ 'messages': Message; }>' is missing the following properties from type 'Application<{ 'messages': Message; }>': search, connect, init, defaultConfiguration, and 39 more.
System configuration
Module versions Default generated by cli
NodeJS version: 10.16.0
Operating System: Windows 10
Browser Version: Not relevant
React Native Version: Not relevant
Module Loader: npm V 6.9.0
Let me know if I'm doing something wrong.
Thanks for your help and time.
I have the same issue, same system configuration. I am using git bash per https://generator.feathers-plus.com/get-started/
I am getting exactly the same on Ubuntu 18.04, using npm.
I narrowed down the issue to a change in
node_modules/@types/express-serve-static-core/index.d.ts@4.16.6, this code is removed compared to 4.16.0:
export interface Application extends EventEmitter, IRouter, Express.Application {
...
/**
* Configure callback for zero or more envs,
* when no `env` is specified that callback will
* be invoked for all environments. Any combination
* can be used multiple times, in any order desired.
*
* Examples:
*
* app.configure(function(){
* // executed for all envs
* });
*
* app.configure('stage', function(){
* // executed staging env
* });
*
* app.configure('stage', 'production', function(){
* // executed for stage and production
* });
*
* Note:
*
* These callbacks are invoked immediately, and
* are effectively sugar for the following:
*
* var env = process.env.NODE_ENV || 'development';
*
* switch (env) {
* case 'development':
* ...
* break;
* case 'stage':
* ...
* break;
* case 'production':
* ...
* break;
* }
*/
configure(fn: Function): Application;
configure(env0: string, fn: Function): Application;
configure(env0: string, env1: string, fn: Function): Application;
configure(env0: string, env1: string, env2: string, fn: Function): Application;
configure(env0: string, env1: string, env2: string, env3: string, fn: Function): Application;
configure(env0: string, env1: string, env2: string, env3: string, env4: string, fn: Function): Application;
To see the effect, add older version of the package:
npm i -D @types/express-serve-static-core@4.16.0
It makes the error go away, log.start:
> feathers-app@0.0.0 start C:\dev\feathers-app
> ts-node --files src/
info: Feathers application started on http://localhost:3030
By no means it is a true fix, just a workaround, as it merely plugs the type discrepancy with some unrelated function signatures.
Thanks @iva2k ! I will definetly look at this "fix" when I have time if there is no official fix.
update /src/app.interface.ts
could fix it
-import { Application } from '@feathersjs/express';
+import { Application } from '@feathersjs/feathers';
@Ticore Your fix is the proper way for doing it. Removes bunch of other TypeScript issues down the road as well.
This fix should be rolled into the generator IMHO.
This does not work for me because when I add multi-part upload according to official guide here, I am calling app.use(path, ...handlers, opts?)
signature from @feathers/express
, not app.use(path, handler, opts?)
signature from @feathers/feathers
.
What ended up working for me is leaving the @feathersjs/express
import statement as-is, but add
import { Application as BaseApplication } from '@feathersjs/feathers';
and then change signature to export type App = BaseApplication & Application<{...}>;
I had the same issues as @khuongduybui and attempted his workaround, only to be greeted by a third error in sequelize.
What worked, surprisingly, was switching the BaseApplication and Application imports, ie.
import { Application as BaseApplication } from '@feathersjs/express';
import { Application } from '@feathersjs/feathers';
Unfortunately this project seems no longer active. Thanks for posting the workaround anyway.