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
any
show 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
And then leave you existing
scripts
in package.json as normal, for example25% strictness
To increase the strictness of JSDoc in a codebase you can add
strict: false
to your jsconfig.jsonThen you can enforce
tsc
in yourpackage.json
so that it fails the test suite like you would use a linter (eslint
orstandard
)50% strictness
The next step for having strict static typed javascript with JSDoc is to turn
strict: true
in thejsconfig.json
.Nothing else really changes
90% strictness
Out of the box
tsc
is suprisingly lenient when it comes to type checking JavaScript, you want to useeslint
There's a seperate discussion about eslint + jsdoc but here i will use
tsdocstandard
as an example100% strictness
The best way to get 100% type safety in a JavaScript + JSDoc project is to use the
type-coverage
command, you can add this to your package.jsonBy asking
type-coverage
you will know you are 100% strict, aka 0% anyBeta Was this translation helpful? Give feedback.
All reactions