[Proof of concept] The ultimate TypeScript setup rework#1975
Closed
aweebit wants to merge 27 commits intotj:developfrom
Closed
[Proof of concept] The ultimate TypeScript setup rework#1975aweebit wants to merge 27 commits intotj:developfrom
aweebit wants to merge 27 commits intotj:developfrom
Conversation
This reverts commit 5c5c972. Reverted for the cae a different suggestion with a fix for that script is accepted.
Fixes type errors revealed after enabling useUnknownInCatchVariables
The checkJs TSConfig option will be used instead. (Most of the directives were misplaced anyway.)
In the test file, an aggregating import (import * as commander) was used to allegedly import the default export. That is not the same as actually importing the default export (import commander). Fixing the import revealed the following error: TS1192: Module '".../commander.js/typings/index"' has no default export. The reason is that the default export is not publicly declared because it is deprecated, and so should not be used. The test was therefore unnecessary.
The aggregated import (import * as commander) doesn't deliver all expected functions when "esModuleInterop": true is set in TSConfig, including when set implicitly because "module" is set to "node16" or "nodenext", like is now the case in our TSConfig after the last commit. The new test block covers that.
- Generate typings automatically from JSDoc (npm run build) - Modularize TSConfig: use separate config files - for lib (with typings generation) - for Jest tests (with Jest types, checks are opt-in for now) - for tsd tests - Use project references in root TSConfig (so that only one tsc run is needed) - Remove typescript-checkJS script. Add typecheck, typecheck-jest and typecheck-all instead
Inspired by SvelteKit (https://github.com/sveltejs/kit) Motivation: - the entry points are indeed part of the library source code - simplifies lint:javascript script and files field in package.json - elimintates the need for "rootDir": ".." in TSConfig for lib (there are no more typings emitted for untracked JS files in the root directory, for example config files and files with quick tests/demos)
c0e79ae to
7bb970b
Compare
The original, manually written typings are kept in the repo for now because they still have to be moved to JSDoc which currently differs from them in a lot of places.
7bb970b to
f384ecf
Compare
This was referenced Aug 15, 2023
Closed
Collaborator
|
This is an interesting refactor, but not something I think we would adopt. If we went all-in on typing then I think it is more likely we would switch to TypeScript implementation. We do certainly have parallel JSDoc and TSDoc, but a benefit is tailoring the two interfaces separately. (Although I wouldn't recommend this in a new program!) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Core components of this PR
.d.tstypings automatically from JSDoc (see TypeScript docs) withnpm run buildlib, Jest tests and tsd tests)typescript-checkJSscript. Addtypecheck,typecheck-jestandtypecheck-allinstead (Jest tests are currently not included intypecheck)test-typingsscript now also includes a typecheckindex.jsandesm.mjstolibwhere they belong (tolib/exports, to be precise)@api privatewith@packagealthough unfortunately both mean nothing to TypeScript, more information at On@apiJSDoc tag #1949Why generate
.d.tsfrom JSDoc?.d.tsand JSDoc like currently.d.ts.d.tsis required@packageoutside Commander is not prevented by TypeScript, but that has little to do with this PR. See #1949 (comment) for detailsTODO
.d.ts.d.tsfiles to `.gitignore? (Svelte does that for example)See also