karma-webpack icon indicating copy to clipboard operation
karma-webpack copied to clipboard

Add type checking to source files

Open matthieu-foucault opened this issue 7 years ago • 8 comments

Expected Behavior / Situation

Not having bugs due to type errors

Actual Behavior / Situation

We have bugs such as #375 and #355 that wouldn't be there with static type checking

Modification Proposal

Build the source code with typescript

matthieu-foucault avatar Nov 30 '18 18:11 matthieu-foucault

@matthieu-foucault my recommendation doesn't rewrite code on typescript because it is hard maintenance for other developers, who not familiar with typescript and there are a lot of such contributors.

In webpack we use Typescript comments like this https://github.com/webpack/webpack/blob/master/lib/Compiler.js#L37. It is allow to static type checking and other developers easy work with code (you can merge PRs and late add types).

alexander-akait avatar Dec 13 '18 21:12 alexander-akait

Nice!, I didn't know that was possible, thanks for the tip!

For future reference, here's the documentation for that: https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html

matthieu-foucault avatar Dec 13 '18 21:12 matthieu-foucault

So the idea is to keep js as is (just add some typescript definition files + jsdocs) but still run a check via typescript?

that actually sounds really nice :)

daKmoR avatar Dec 13 '18 22:12 daKmoR

@daKmoR yep, you can look setup in webpack repo :+1:

alexander-akait avatar Dec 13 '18 22:12 alexander-akait

@evilebottnawi at this wip you can see my intial attempt at starting type linting - can you pls check if it's the right direction?

also would we still need to generate type definition files or are the js doc hints good enough? If there would be a need to generate them any sugguestion on howto? I looked at the webpack setup but that seems rather complex 🙈

daKmoR avatar Dec 19 '18 00:12 daKmoR

Generating the typedefs is done simply by adding "declaration": true to the tsconfig compilerOptions, and adding a "types": "./lib/main.d.ts" entry to the package.json.

The other option is to publish under @types/karma-webpack, which may be the preferred way (at least that seems to be what webpack is doing).

Either way, I don't think that publishing the type declarations would have much of an impact (unless someone writes something that extends karma-webpack :fearful: )

matthieu-foucault avatar Dec 19 '18 00:12 matthieu-foucault

Generating the typedefs is done simply by adding "declaration": true to the tsconfig compilerOptions, and adding a "types": "./lib/main.d.ts" entry to the package.json.

@matthieu-foucault hmm that does not seem to work? I would expect that a file ./lib/main.d.ts get's generated if I run ./node_modules/.bin/tsc --declaration

daKmoR avatar Dec 30 '18 00:12 daKmoR

Sorry, just noticed that comment now: might be because of the noEmit option?

matthieu-foucault avatar Jan 02 '19 23:01 matthieu-foucault

As karma is now deprecated and coming up on EOL, we are no longer planning on any significant enhancements to this project and are instead going to focus on security updates, stability, and a migration path forward as karma's lifecycle comes to an end.

Thank you for supporting and using this project!

codymikol avatar Oct 22 '23 01:10 codymikol