feat: convert the package into TypeScript#509
Conversation
|
FWIW when I import this like Could not find a declaration file for module '@dagrejs/dagre'. 'c:/Users/jgc/source/repos/gms-api/ui/node_modules/@dagrejs/dagre/dist/dagre.esm.js' implicitly has an 'any' type. |
1ca7425 to
5a15c8d
Compare
|
Thanks @celluj34 for reporting the error. I forgot to add the dist folder in my package. It is fixed now. |
|
The Typescript Graphlib package from dagrejs/graphlib#224 works perfectly with this version since there are no breaking changes. |
c509f33 to
67e7190
Compare
|
The tests in the github workflow are finally working as expected @rustedgrail
.
|


Overview
This PR migrates the entire
@dagrejs/dagrecodebase from JavaScript to TypeScript (native source, not just type declarations). All source files, tests, and tooling scripts have been converted, and the build pipeline has been updated accordingly.It's linked to dagrejs/graphlib#223.
Why
@dagrejs/dagrehas been shipping a hand-writtenindex.d.tsalongside its JavaScript source for a while. This approach is inherently fragile, the type declarations and the actual implementation are two separate things that have to be kept in sync manually. I ran into type drift issues and decided the cleanest fix was to rewrite the source in TypeScript directly, so types and implementation can never diverge again.What changed
Source & Tests
lib/**/*.js→.ts(layout engine, ordering, ranking, positioning, utilities)test/**/*.js→.tsbuild.js,src/**/*.js) →.tslib/types.tswith shared interfaces and type aliases used across the codebaseindex.d.ts— types are now generated directly from the sourceTooling
build.jswithbuild.ts(run viatsx)tsconfig.json(strict mode) andtsconfig.build.jsonfor declaration emittsconfig.test.jsonfor Jest/ts-jest configurationjest.config.jswithjest.config.tsusingts-jest.eslintrc.jsonto use@typescript-eslintparser and plugintypecheck,bench,version:check,version:bump,version:makeprepublishOnlyto ensure typecheck, lint, tests, and build always pass before publishingTypes output
index.d.tstsc -p tsconfig.build.jsonintodist/types/exportsandtypesfields inpackage.jsonto point todist/types/index.d.tsAdvantages of the TypeScript version
index.d.ts).d.tsstubs).d.ts)@typescript-eslint,tsx,ts-jestBreaking changes
3.0.0-pre— this is a major version given the nature of the migration and the removal of the old hand-written declaration file.typesentry point has moved fromdist/dagre.d.tstodist/types/index.d.ts. If you reference the type path directly (e.g. inpathsintsconfig.json), update accordingly. Theexportsfield handles this automatically for modern toolchains.