Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handshake/Bcoin - Add typescript type linter support #841

Open
19 of 32 tasks
nodech opened this issue Aug 11, 2023 · 2 comments
Open
19 of 32 tasks

Handshake/Bcoin - Add typescript type linter support #841

nodech opened this issue Aug 11, 2023 · 2 comments

Comments

@nodech
Copy link
Contributor

nodech commented Aug 11, 2023

Motivation

bcoin-org and handshake-org dependencies actively use JSDocs to document types in the codebase. Unfortunately, they don't provide anything more useful than the documentation, they are not used for the type checking. In the end documentation sometimes becomes incorrect and goes out of sync and there's no easy way to detect those.
TypeScript support for the JSdoc but with several differences. It can allow us to check the code for the proper types and detect when either types go out of sync. It can also help with code analyses in some cases and catch when something does not have proper type etc. It is not all powerful but is an improvement over what we have.
In general, bcoin-org/handshake-org projects don't want to introduce dependencies to the projects if possible and especially not the another step in development process (e.g. transpiling). But what we can use are external tools to verify the code quality (linter).
This is a proposal to use tsc externally as a type linter, but don't use it for anything more. Developers don't have any strict requirement to install them locally (similar to linter) and can just rely on the CI to lint them.
This change was inspired by the svelte: sveltejs/svelte#8569

Relationship with jsdoc reference

Some syntax in TypeScript is not supported by the jsdoc reference generator, for that purpose we can remove them in the jsdoc reference generator.
Here's a fix for the typedef imports: pinheadmz/bsdoc#1

Implementation

TypeScript needs types for the builtin nodejs types which are not built into it. This in general is provided by: https://github.com/DefinitelyTyped/DefinitelyTyped To avoid extra dependencies to the project the necessary type aliases are
vendored here: https://github.com/bcoin-org/bts-type-deps

There are already several PRs that have these changes, but are not merged yet to allow for the feedback. Here's the short list of them (Some of them have linter on ci failing, because dependencies are not published)
Goal is not to fully fix everything in one go, but to allow slow incremental improvements. Current list of PRs do mostly minimal work to suppress or fix types in the dependencies. Slowly we can iterate and fix these.
Handshake and bcoin both can enable type lints slowly starting from simpler modules (e.g. primitives) and slowly expand the tsc-lint support everywhere.
Here's the list of current PRs:

@pcfreak30
Copy link

Kudos, finally glad to see this happening. I know its grunt work to do it, but also AI can probably speed it along from experience.

@nodech
Copy link
Contributor Author

nodech commented Aug 22, 2024

This is currently blocked by the bug in tsc: microsoft/TypeScript#55875

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants