TS2344 errors in published declarations with `exactOptionalPropertyTypes` and `skipLibCheck: false`
What platform were you using when you found the bug?
- React Flow / Svelte Flow version:
@xyflow/react12.12.0 (@xyflow/system0.0.83); also 12.11.6 - Browser and version: n/a (type-checking only; TypeScript 5.9.3 and 7.0.2)
- OS and version: Linux (not OS-specific)
Live code example
n/a: type-checking only; a three-file reproduction is under "Steps to reproduce"
Describe the Bug
With exactOptionalPropertyTypes: true and skipLibCheck: false, type-checking a file that imports @xyflow/react fails with 19 TS2344 errors. All of them are inside the published declaration files (2 in @xyflow/react, 5 in @xyflow/system). The application code has no errors; it's a declaration-only problem.
node_modules/@xyflow/react/dist/esm/hooks/useConnection.d.ts(32,102): error TS2344: Type 'InternalNode<NodeType>' does not satisfy the constraint 'InternalNodeBase'.
Type 'InternalNode<NodeType>' is not assignable to type 'Omit<NodeBase<Record<string, unknown>, string | undefined>, "measured">' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
Types of property 'origin' are incompatible.
Type 'NodeType["origin"]' is not assignable to type 'NodeOrigin'.
Type 'NodeOrigin | undefined' is not assignable to type '[number, number]'.
Type 'undefined' is not assignable to type '[number, number]'.Cause: NodeBase declares its optional fields as field?: T. InternalNodeBase<NodeType> is built with Omit<NodeType, 'measured'> over a generic NodeType, so each field's type becomes NodeType['field'], whose constraint is T | undefined. With exactOptionalPropertyTypes, T | undefined is not assignable to field?: T, so every place where InternalNodeBase<NodeType> has to satisfy the plain InternalNodeBase constraint fails. TypeScript names only the first incompatible field per error; fixing that field exposes the next one, and 21 fields are affected in total.
Steps to reproduce the bug or issue
- Create these three files:
package.json
{
"private": true,
"type": "module",
"dependencies": {
"@xyflow/react": "12.12.0",
"react": "19.2.8",
"react-dom": "19.2.8"
},
"devDependencies": {
"@types/react": "19.2.18",
"typescript": "5.9.3"
}
}tsconfig.json
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022", "DOM"],
"module": "ESNext",
"moduleResolution": "Bundler",
"jsx": "react-jsx",
"strict": true,
"exactOptionalPropertyTypes": true,
"skipLibCheck": false,
"noEmit": true
},
"include": ["index.tsx"]
}index.tsx
import { ReactFlow, type Edge, type Node } from '@xyflow/react';
const nodes: Node[] = [{ id: '1', position: { x: 0, y: 0 }, data: { label: 'Node' } }];
const edges: Edge[] = [];
export function App() {
return <ReactFlow nodes={nodes} edges={edges} />;
}- Run
npm install, thennpx tsc. - See 19 TS2344 errors, all under
node_modules/@xyflow/. TypeScript 7.0.2 reports the same 19.
Either --skipLibCheck or --exactOptionalPropertyTypes false makes the errors go away, which may be why this hasn't come up: most projects skip library checks, and this repository's tooling/tsconfig/base.json uses skipLibCheck: true without exactOptionalPropertyTypes.
Expected behavior
As a user, I expected the published declarations to type-check with exactOptionalPropertyTypes: true and skipLibCheck: false, but instead I am seeing 19 TS2344 errors from inside @xyflow/react and @xyflow/system.
Screenshots or Videos
No response
Additional context
Suggested fix: add | undefined to the 21 optional fields of NodeBase in packages/system/src/types/nodes.ts, the same form that type?: string | undefined already uses in that type:
sourcePosition, targetPosition, hidden, selected, dragging, draggable, selectable, connectable, deletable, dragHandle, width, height, initialWidth, initialHeight, parentId, zIndex, extent, expandParent, ariaLabel, origin, handles
- width?: number;
+ width?: number | undefined;measured doesn't need it, because InternalNodeBase omits that field.
With this change applied to the published nodes.d.ts, the reproduction type-checks with zero errors on both TypeScript 5.9.3 and 7.0.2. Projects that don't enable exactOptionalPropertyTypes aren't affected: for them, field?: T already accepts undefined, so the change only makes the declarations consistent for projects that do.
I'm happy to open a PR with this change and a changeset.
Source: xyflow/xyflow