Adopting JSDoc with varying levels of strictness. #9
Replies: 4 comments 2 replies
-
|
@Raynos is that |
Beta Was this translation helpful? Give feedback.
-
|
@rizary that was a typo I meant |
Beta Was this translation helpful? Give feedback.
-
|
As for example project see https://github.com/Raynos/lean.js/blob/master/package.json or any other project referenced from tsdocstandard ( https://github.com/Raynos/tsdocstandard#status-unstable ). |
Beta Was this translation helpful? Give feedback.
-
|
I myself often play around with modifiers on top of "noImplicitAny": false,
"strictNullChecks": false,Then reactivating them as I move towards an ever stricter setup and then combining it with https://github.com/voxpelli/eslint-config-jsdoc-ts and since @Raynos suggested |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When using JSDoc together with typescript you can enforce varying levels of strictness as part of your tests, test suite & CI setup.
When we talk about strictness what we mean is "How many times does the type
anyshow up in your codebase", aka if your project is 50% strict, that means its 50% statically typed & 50% "any" typed.0% strictness (IDE only)
To use JSDoc with no strictness you can add a very simple
jsconfig.json{ "compilerOptions": { "target": "es2018", "lib": ["es2018", "dom"], "noEmit": true, "module": "commonjs", "moduleResolution": "node", "resolveJsonModule": true }, "exclude": ["node_modules"], "include": [ "src/**/*.js", "src/**/*.d.ts" ] }And then leave you existing
scriptsin package.json as normal, for example{ "scripts": { "test": "node test/index.js" } }25% strictness
To increase the strictness of JSDoc in a codebase you can add
strict: falseto your jsconfig.json{ "compilerOptions": { ... "strict": false, } }Then you can enforce
tscin yourpackage.jsonso that it fails the test suite like you would use a linter (eslintorstandard){ "scripts": { "tsc": "tsc -p jsconfig.json --maxNodeModuleJsDepth 0", "test": "npm run tsc && node test/index.js" } }50% strictness
The next step for having strict static typed javascript with JSDoc is to turn
strict: truein thejsconfig.json.Nothing else really changes
90% strictness
Out of the box
tscis suprisingly lenient when it comes to type checking JavaScript, you want to useeslintThere's a seperate discussion about eslint + jsdoc but here i will use
tsdocstandardas an example{ "scripts": { "tsc": "tsc -p jsconfig.json --maxNodeModuleJsDepth 0", "test": "npm run tsc && tsdocstandard && node test/index.js" } }100% strictness
The best way to get 100% type safety in a JavaScript + JSDoc project is to use the
type-coveragecommand, you can add this to your package.json{ "scripts": { "tsc": "tsc -p jsconfig.json --maxNodeModuleJsDepth 0", "test": "npm run tsc && tsdocstandard && node test/index.js && npm run type-coverage", "type-coverage": "type-coverage -p jsconfig.json --ignore-catch --strict --at-least 100" } }By asking
type-coverageyou will know you are 100% strict, aka 0% anyBeta Was this translation helpful? Give feedback.
All reactions