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

feat(allow-scripts): generate & ship typescript declarations #675

Merged
merged 2 commits into from
Oct 5, 2023

Conversation

boneskull
Copy link
Contributor

This is a PoC for creating (and shipping) declaration files for LavaMoat packages.

Right now, I've fully typed the sources (not the tests) of @lavamoat/allow-scripts, which now validates the types in "strict" mode. TypeScript is configured for incremental builds (preferable for monorepos), but only builds one module as a PoC.

To generate types, execute npm run build:types in the @lavamoat/allow-scripts workspace. They will be output into packages/allow-scripts/types (which is not under VCS).

I added available type declarations (from DefinitelyTyped), but I had to write a handful of my own for external modules. These do not appear to be re-exported. AFAICT (but I haven't tested it!) there aren't any type declarations that are needed as production dependencies (in @lavamoat/allow-scripts, anyway).

I took some liberties tweaking existing types (narrowing where appropriate, separating @typedefs so that descriptions would be picked up, etc.). I'd prefer if we used the T[] syntax for arrays instead of Array, but that's just my personal preference and I stuck to the current convention.

I note that these .d.ts files I created have semicolons which is a byproduct of my IDE's default formatting. If we intend to keep any of these around, I'd recommend pulling in @typescript-eslint/plugin and its ilk.

@boneskull
Copy link
Contributor Author

boneskull commented Aug 22, 2023

@boneskull
Copy link
Contributor Author

This is the same as #617, which was closed due to Reasons.

@boneskull boneskull added the enhancement New feature or request label Aug 23, 2023
@boneskull boneskull self-assigned this Aug 23, 2023
@boneskull boneskull requested a review from a team August 23, 2023 00:06
@boneskull boneskull requested a review from a team August 28, 2023 19:45
@boneskull boneskull force-pushed the boneskull/ts branch 3 times, most recently from 358cc18 to 5b8795c Compare August 30, 2023 17:54
@boneskull boneskull changed the base branch from main to boneskull/npm-not-that-new September 1, 2023 22:43
@boneskull boneskull changed the base branch from boneskull/npm-not-that-new to main September 8, 2023 21:33
@boneskull boneskull force-pushed the boneskull/ts branch 6 times, most recently from a44e35c to 7abf2ef Compare September 15, 2023 21:15
@boneskull boneskull force-pushed the boneskull/ts branch 3 times, most recently from 7f857a0 to f9f4cd7 Compare September 25, 2023 20:38
This adds `.d.ts` generation to `@lavamoat/allow-scripts`.

- Many type defs added to `src/types` for those modules which do not have them (nor are there any published to DefinitelyTyped).  In the future, some of these could be submitted to DefinitelyTyped, if we wish.
- Upgrade `yargs`
- Create reusable TS configuration supporting incremental builds
- Declaration files generated at build time and shipped in the `types` folder (which is now in `.gitignore`)
- Created `.depcheckrc`
- Added, updated, removed and/or fixed many docstring types

Note: the uncommon `skipLibCheck = false` setting in this module's `tsconfig.json` enables typechecking of the `.d.ts` files themselves.  These files are not compiled.
Copy link
Contributor

@leotm leotm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps a cheeky prettier write before merging? since we merged #725

Screenshot 2023-10-05 at 3 01 18 pm

package.json Show resolved Hide resolved
@boneskull boneskull merged commit 3f7c381 into main Oct 5, 2023
11 checks passed
@boneskull boneskull deleted the boneskull/ts branch October 5, 2023 17:58
@github-actions github-actions bot mentioned this pull request Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants