feathers-plus / cli

FeathersJS CLI supporting both REST and GraphQL architectural concepts and their query languages.
https://generator.feathers-plus.com/
Other
43 stars 7 forks source link

Generated TypeScript version fails to compile - app.configure() type mismatch #37

Closed iva2k closed 4 years ago

iva2k commented 5 years ago

Steps to reproduce

Using Windows7, node v8.11.2, Performed the following steps from https://generator.feathers-plus.com/get-started/

npm i -g @feathers-plus/cli
#  + @feathers-plus/cli@0.8.10
mkdir feathers-app
cd feathers-app
feathers-plus generate options
# chosen all defaults, except "Generate TypeScript code?" Yes

feathers-plus generate app
# chosen all defaults (npm is installed package manager)

npm start > log.start 2>&1
# -> fails

Expected behavior

Server should start

Actual behavior

TypeScript compilation fails, log.start:


> feathers-app@0.0.0 start C:\dev\feathers-app
> ts-node --files src/

C:\dev\feathers-app\node_modules\ts-node\src\index.ts:261
    return new TSError(diagnosticText, diagnosticCodes)
           ^
TSError: ⨯ Unable to compile TypeScript:
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<{}>': map, patch, init, defaultConfiguration, and 39 more.
src/app.ts(78,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 not assignable to type 'Application<{}>'.
src/app.ts(80,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 not assignable to type 'Application<{}>'.

    at createTSError (C:\dev\feathers-app\node_modules\ts-node\src\index.ts:261:12)
    at getOutput (C:\dev\feathers-app\node_modules\ts-node\src\index.ts:367:40)
    at Object.compile (C:\dev\feathers-app\node_modules\ts-node\src\index.ts:558:11)
    at Module.m._compile (C:\dev\feathers-app\node_modules\ts-node\src\index.ts:439:43)
    at Module._extensions..js (module.js:663:10)
    at Object.require.extensions.(anonymous function) [as .ts] (C:\dev\feathers-app\node_modules\ts-node\src\index.ts:442:12)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! feathers-app@0.0.0 start: `ts-node --files src/`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the feathers-app@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\...\AppData\Roaming\npm-cache\_logs\2019-06-03T17_06_04_691Z-debug.log

System configuration

Tell us about the applicable parts of your setup.

Module versions (especially the part that's not working): @feathers-plus/cli@0.8.10

NodeJS version: v8.11.2 v11.4.0 (also tried with, using nvm)

Operating System: Windows 7

Module Loader: npm 6.9.0

iva2k commented 5 years ago

I narrowed down the issue to 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
matt-sanders commented 5 years ago

+1 on this. I'm also having trouble when trying to add authentication. It seems like even with the above fix I still run into issues:

feathers-plus generate options
# select all the defaults, except select typescript

feathers-plus generate app
# select all defaults

feathers-plus generate authentication
# select all defaults

npm i -D @types/express-serve-static-core@4.16.0

npm start

The above will fail

frankeros commented 5 years ago

+1 same here! Any notice of this?

soorur commented 5 years ago

Yes - im blocked also by this.

Any ideas what to downgrade?

@eddyystop

Ziao commented 5 years ago

Any updates on this? Long time Feathers developer, would love to get started with Typescript. This one is preventing that. Cheers :)

larrybolt commented 5 years ago

@Ziao I'm not sure whether this is "the" fix, but looking around it looks like this could fix it:

// in ./src/app.interface.ts, end of the file
export type App = Application<{
  'accounts': Account,
  'users': User,
  'authentication': any, // THIS
  // !code: moduleExports // !end
}>;

I'm very very new to Feathers though

iva2k commented 5 years ago

For proper fix see https://github.com/feathers-plus/generator-feathers-plus/issues/276#issuecomment-506623592

blackholegalaxy commented 5 years ago

It also could need Authentication as any in Application in certain cases. We fixed this in our own feathers-plus implementation along with other TS features like Enums. Will open a PR soon. Or maybe wait for v4.