panuhorsmalahti / gulp-tslint

TypeScript linter plugin for Gulp
MIT License
118 stars 44 forks source link

type definitions for gulp-tslint dont work with typescript #124

Open damons-sportsbet opened 7 years ago

damons-sportsbet commented 7 years ago

I'm not sure how this is possible, but the built in type definitions for gulp-tslint itself don't work for me when trying to use a typescript gulpfile.

A lot of libraries that export a function that has members on it, like, say, mkdirp, or express, use a method where they define a function and then a namespace with the same name. The function defines the exported function and the namespace defines any members that are also on that function. This process seems to work.

The strategy that gulp-tslint uses is this: export interface TslintPlugin { (pluginOptions?: PluginOptions): any; report: (options?: ReportOptions) => any; }

which absolutely should work, but doesn't seem to actually work for us, perhaps it's because we are using the node style module loader for typescript?

Anyway, the type definitions from definitelyTyped, that are now available as the npm package @types/gulp-tslint do seem to work for me so I wonder if you can just take those ones and use them?

gulp-tslint version: 8.0.0 tslint version: 5.0.0 Operating system: MacOS

Example gulp configuration (if applicable):

gulpfile.txt

Error console output: gulpfile.ts (140,10): Cannot invoke an expression whose type lacks a call signature. Type 'typeof "/Users/damons/Work/Sportsbet/hydra/node_modules/gulp-tslint/index"' has no compatible call signatures. (2349) gulpfile.ts (141,15): Property 'report' does not exist on type 'typeof "/Users/damons/Work/Sportsbet/hydra/node_modules/gulp-tslint/index"'. (2339)

TypeScript example code (if applicable):

panuhorsmalahti commented 7 years ago

I'll release 8.1.0 today, which will contain some changes to the types: https://github.com/panuhorsmalahti/gulp-tslint/pull/119 - maybe that will help here.

EDIT: published, can you try again?

You could also try import tslint from "gulp-tslint";

damons-sportsbet commented 7 years ago

Hi Panu, it didn't work for me, TS still can't resolve an interface with a default function definition, even though it should work and TS doesn't complain about the definition at all. I raised a PR (https://github.com/panuhorsmalahti/gulp-tslint/pull/128) which fixes it for me, hope you get a chance to review it.

panuhorsmalahti commented 7 years ago

What do you mean by node style module loader for typescript? Can you link to a repository which exhibits the problem?

damons-sportsbet commented 7 years ago

Hi again, ok here's an example app that demonstrates the problem:

https://github.com/damon-at-sportsbet/types-test-gulp-tslint

if you check out that project and run npm install and then npm run test you'll see what I mean. The type definitions that you have might work internally when developing the plugin, but they don't work externally when importing it as a module and using it in a typescript gulpfile.

I have had some discussion with people and had it explained to me why this is such a nightmare to do in a nice way. If you want I can try to explain that here too.

damons-sportsbet commented 7 years ago

Ok for now I guess I'm going to have to fork this project. Shame.