{"id":10967,"library":"graphology-types","title":"Graphology TypeScript Types","description":"graphology-types provides comprehensive TypeScript declaration files for the `graphology` graph manipulation library. Its current stable version is 0.26.0, released in alignment with `graphology`'s development, ensuring type definitions are up-to-date with the core library's API. This package is crucial for developers building type-safe applications with `graphology` in TypeScript environments, offering static checking for graph structures, node and edge attributes, and various graph operations. As an official types package, it guarantees accurate and reliable type information, distinguishing it from community-maintained declaration files which might fall out of sync with library updates. It helps prevent common runtime errors by catching type mismatches at compile time, enhancing developer experience and code maintainability.","status":"active","version":"0.24.8","language":"javascript","source_language":"en","source_url":"https://github.com/graphology/graphology","tags":["javascript","graph","graphology","types","typescript"],"install":[{"cmd":"npm install graphology-types","lang":"bash","label":"npm"},{"cmd":"yarn add graphology-types","lang":"bash","label":"yarn"},{"cmd":"pnpm add graphology-types","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides type definitions for the graphology library; typically used as a peer dependency alongside the main graphology package.","package":"graphology","optional":false}],"imports":[{"note":"Imports the Graph *interface* for type declarations, not the Graph class itself. The actual Graph class is imported from 'graphology'.","wrong":"import Graph from 'graphology-types';","symbol":"Graph","correct":"import { Graph } from 'graphology-types';"},{"note":"Standard import for the base interface representing node attributes. Extend this interface for custom attribute types.","symbol":"NodeAttributes","correct":"import { NodeAttributes } from 'graphology-types';"},{"note":"Standard import for the base interface representing edge attributes. Extend this interface for custom attribute types.","symbol":"EdgeAttributes","correct":"import { EdgeAttributes } from 'graphology-types';"}],"quickstart":{"code":"import Graph from 'graphology';\nimport { Graph as GraphType, NodeAttributes, EdgeAttributes } from 'graphology-types';\n\n// Define custom interfaces for node and edge attributes\ninterface MyNodeAttributes extends NodeAttributes {\n  name: string;\n  weight?: number;\n}\n\ninterface MyEdgeAttributes extends EdgeAttributes {\n  type: 'friend' | 'family';\n  since: Date;\n}\n\n// Instantiate a graph with specific types for node and edge attributes\nconst graph: GraphType<MyNodeAttributes, MyEdgeAttributes> = new Graph<MyNodeAttributes, MyEdgeAttributes>();\n\n// Add nodes with type-checked attributes\ngraph.addNode('john', { name: 'John Doe', weight: 80 });\ngraph.addNode('jane', { name: 'Jane Smith' });\n\n// Add edges with type-checked attributes\ngraph.addEdge('john', 'jane', { type: 'friend', since: new Date('2020-01-01') });\n\n// Access attributes with type inference\nconst johnsName: string = graph.getNodeAttribute('john', 'name');\nconst edgeType: 'friend' | 'family' = graph.getEdgeAttribute('john', 'jane', 'type');\n\nconsole.log(`John's name: ${johnsName}`);\nconsole.log(`Relationship type: ${edgeType}`);\nconsole.log(`Graph order: ${graph.order}`);\nconsole.log(`Graph size: ${graph.size}`);","lang":"typescript","description":"Demonstrates how to define and use a `graphology` graph with custom type-safe node and edge attributes using `graphology-types`."},"warnings":[{"fix":"Ensure your project's module resolution (e.g., `tsconfig.json` `moduleResolution`) is configured correctly for 'NodeNext' or 'Bundler' if using ESM, and update `graphology` to a compatible version if facing runtime import issues.","message":"Version `0.26.0` introduces ESM support across the `graphology` ecosystem. While `graphology-types` primarily provides declaration files, this change in the underlying library may impact how `graphology` is imported and subsequently how types are resolved in mixed CJS/ESM projects.","severity":"breaking","affected_versions":">=0.26.0"},{"fix":"Review custom type definitions or interfaces that might have implicitly relied on `obliterator` types. Update code to use standard JavaScript iteration protocols or `graphology`'s native iteration methods.","message":"The `obliterator` dependency was removed in version `0.26.0`. While this is primarily an internal change, if any type definitions from `obliterator` were inadvertently exposed or relied upon in custom extensions, their removal could lead to type errors.","severity":"breaking","affected_versions":">=0.26.0"},{"fix":"Refactor code to use supported graph conversion methods or ensure only documented APIs are accessed. Consult the `graphology` documentation for official upgrade paths.","message":"Version `0.24.0` removed undocumented methods `#.upgradeToMixed` and `#.upgradeToMulti` from the `Graph` class. Although undocumented, if these methods were used, their removal will result in type and runtime errors.","severity":"breaking","affected_versions":">=0.24.0"},{"fix":"Review usage of `setEdgeAttribute`, `getEdgeAttribute`, etc., and ensure they conform to the updated (and officially documented) function signatures for attribute handling.","message":"Version `0.24.0` also includes 'Dropping some irrelevant arities for edge attribute' setters/getters. This could lead to type mismatches if custom attribute functions or specific parameter counts were expected when interacting with edge attributes.","severity":"breaking","affected_versions":">=0.24.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Run `npm install graphology-types` or `yarn add graphology-types`. Ensure `tsconfig.json` includes `node_modules/@types` in its `typeRoots` or that the package is correctly referenced.","cause":"The `graphology-types` package has not been installed or TypeScript cannot locate its declaration files.","error":"TS2307: Cannot find module 'graphology-types' or its corresponding type declarations."},{"fix":"Extend `NodeAttributes` or `EdgeAttributes` with your custom properties, e.g., `interface MyNodeAttrs extends NodeAttributes { xyz: string; }` and use `Graph<MyNodeAttrs>`.","cause":"Attempting to access a node or edge attribute that has not been explicitly defined in the custom `NodeAttributes` or `EdgeAttributes` interface.","error":"Property 'xyz' does not exist on type 'NodeAttributes'."},{"fix":"Ensure that the values passed to `addNode`, `setNodeAttribute`, etc., strictly conform to the types defined in your custom attribute interfaces.","cause":"A type mismatch occurs when setting or retrieving an attribute, where the value provided does not match the type defined in the custom `NodeAttributes` or `EdgeAttributes` interface.","error":"Argument of type 'number' is not assignable to parameter of type 'string'."},{"fix":"Verify the exact name of the type or interface you are trying to import from the `graphology-types` documentation or its `d.ts` files. Ensure you are using named imports for interfaces and types.","cause":"An incorrect named import was used, or the symbol 'X' does not exist in the `graphology-types` package.","error":"Module 'graphology-types' has no exported member 'X'. Did you mean 'Y'?"}],"ecosystem":"npm"}