feat: convert the package into TypeScript#223
Merged
rustedgrail merged 4 commits intodagrejs:masterfrom Mar 8, 2026
Merged
Conversation
Contributor
Author
|
I have update the PR to have ISO types. and I have added this part to the description
|
Collaborator
|
Thanks for doing this! Looks like there is a missing library https://github.com/dagrejs/graphlib/actions/runs/22388294481/job/65239806208?pr=223 |
Contributor
Author
|
Thanks @rustedgrail , I have fixed the github workflow
|
rustedgrail
approved these changes
Mar 8, 2026
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.

Overview
This PR migrates the entire
@dagrejs/graphlibcodebase 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.Why
I've been relying on
dagrejs/dagrefor a while, which depends on@dagrejs/graphlib. And I have met some typing issues in the last updates. I figured the best way to fix it properly was to rewrite the source in TypeScript — so types and implementation can never drift apart again.NO BREAKING CHANGES
The types are isomorphic with the previous types. However, this is artificial.
WARNING 🚨
The migration has revealed real typing errors.
For example, the graph methods should have
graph(): GraphLabel | undefined,node(name: string): NodeLabel | undefined, andedge(v: string | Edge, w?: string, name?: string): EdgeLabel | undefined. This could lead to errors.What changed
Source & Tests
lib/**/*.js→.ts(graph, algorithms, data structures)test/**/*.js→.tsbuild.js,src/**/*.js) →.tslib/types.tsfile with shared interfaces (GraphOptions,Edge,Path) and type aliases (WeightFunction,EdgeFunction,NodeLabelFactory,EdgeLabelFactory)Tooling
build.jswithbuild.ts(run viatsx)tsconfig.json(strict mode) andtsconfig.build.jsonfor declaration emitjest.config.jswithjest.config.tsusingts-jest.jshintrclinting with@typescript-eslinttypecheck,bench,version:check,version:bump,version:makeprepublishOnlyto ensure the build and tests always pass before publishingTypes output
dist/graphlib.d.ts/index.d.tstsc -p tsconfig.build.jsonintodist/types/exportsandtypesfields inpackage.jsonto point todist/types/index.d.tsAdvantages of the TypeScript version
.d.ts).d.tsstubs)Graph<NodeLabel, EdgeLabel>,NodeLabelFactory<T>,EdgeLabelFactory<T>WeightFunction,EdgeFunction,Path.d.ts)@typescript-eslint,tsx,ts-jestBreaking changes
4.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/graphlib.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.