[Docs] Small update to CLI Plugin page for clarity
robbie-johnstone-bjss opened this issue · 1 comments
I'm submitting a...
- Regression
- Bug report
- Feature request
- Documentation issue or request (new chapter/page)
- Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behaviour
The current documentation that covers CLI Plugins has a section that covers getting them to run with ts-jest
tests.
The code example doesn't tell you what the type of cs
is.
In the project I'm working on we're using the ESLint rule no-implicit-any
and additionally aren't willing to use any
as a type itself.
const transformer = require('@nestjs/swagger/plugin');
module.exports.name = 'nestjs-swagger-transformer';
// you should change the version number anytime you change the configuration below - otherwise, jest will not detect changes
module.exports.version = 1;
module.exports.factory = (cs) => {
return transformer.before(
{
// @nestjs/swagger/plugin options (can be empty)
},
cs.program, // "cs.tsCompiler.program" for older versions of Jest (<= v27)
);
};
Expected behaviour
The type of cs
is TsCompilerInstance
which eventually I tracked down here
const transformer = require('@nestjs/swagger/plugin');
import { TsCompilerInstance } from 'ts-jest'
module.exports.name = 'nestjs-swagger-transformer';
// you should change the version number anytime you change the configuration below - otherwise, jest will not detect changes
module.exports.version = 1;
module.exports.factory = (compilerInstance: TsCompilerInstance) => {
return transformer.before(
{
// @nestjs/swagger/plugin options (can be empty)
},
cs.program, // "cs.tsCompiler.program" for older versions of Jest (<= v27)
);
};
What is the motivation / use case for changing the behaviour?
I spent half an hour tracking down what this type was, with the clue being in the comment about using cs.tsCompiler.program
.
I'm fairly new to Typescript and others might be able to do this far quicker, but if it saves someone else 30 minutes IMO it's worth updating.
I'm also not sure what cs
would be an acronym of, or short for.
Why didn't you exclude this file in the eslint configuration? Running eslint on external plugins taken from the docs doesn't seem to be very beneficial