typescript error on example in the docs #26

Closed
opened 2026-02-15 17:05:38 -05:00 by yindo · 21 comments
Owner

Originally created by @willredington on GitHub (May 18, 2024).

This example is throwing an error in typescript and its right from the docs

const schema = {
  input: {
    value: null,
  },
  agentOutcome: {
    value: null,
  },
  steps: {
    value: (x: Array<BaseMessage>, y: Array<BaseMessage>) => x.concat(y),
    default: () => [],
  },
};

const graph = new StateGraph({
  channels: schema, // incorrect type here
});

Using the following versions:

{
    "@langchain/core": "^0.2.0",
    "@langchain/langgraph": "^0.0.17",
    "@langchain/openai": "^0.0.32"
}

The error is:

Property 'root' is missing in type '{ input: { value: null; }; agentOutcome: { value: null; }; steps: { value: (x: Array, y: Array) => BaseMessage[]; default: () => never[]; }; }' but required in type 'ChannelReducers<{ root: unknown; }>'.

Originally created by @willredington on GitHub (May 18, 2024). This example is throwing an error in typescript and its right from the docs ```typescript const schema = { input: { value: null, }, agentOutcome: { value: null, }, steps: { value: (x: Array<BaseMessage>, y: Array<BaseMessage>) => x.concat(y), default: () => [], }, }; const graph = new StateGraph({ channels: schema, // incorrect type here }); ``` Using the following versions: ```json { "@langchain/core": "^0.2.0", "@langchain/langgraph": "^0.0.17", "@langchain/openai": "^0.0.32" } ``` The error is: > Property '__root__' is missing in type '{ input: { value: null; }; agentOutcome: { value: null; }; steps: { value: (x: Array<BaseMessage>, y: Array<BaseMessage>) => BaseMessage[]; default: () => never[]; }; }' but required in type 'ChannelReducers<{ __root__: unknown; }>'.
yindo closed this issue 2026-02-15 17:05:38 -05:00
Author
Owner

@hinthornw commented on GitHub (May 18, 2024):

ya good catch - I did it all in deno at first (so they all do run there) but will have to review and clean up to get the types all correct

@hinthornw commented on GitHub (May 18, 2024): ya good catch - I did it all in deno at first (so they all do run there) but will have to review and clean up to get the types all correct
Author
Owner

@willredington commented on GitHub (May 19, 2024):

Thanks for the response, not critical just getting on the docket

@willredington commented on GitHub (May 19, 2024): Thanks for the response, not critical just getting on the docket
Author
Owner

@hinthornw commented on GitHub (May 20, 2024):

Pushed an update - reran all of them with TS on langgraph 0.0.18 - hopefully resolves things for ya

@hinthornw commented on GitHub (May 20, 2024): Pushed an update - reran all of them with TS on langgraph 0.0.18 - hopefully resolves things for ya
Author
Owner

@bharathvaj-ganesan commented on GitHub (May 20, 2024):

I'm still facing this issue on 0.0.19 version.

@bharathvaj-ganesan commented on GitHub (May 20, 2024): I'm still facing this issue on 0.0.19 version.
Author
Owner

@hinthornw commented on GitHub (May 21, 2024):

For all of the docs? What does your tsconfig look like?

The change wasn't something for the actual StateGraph code, it was just fixing the docs FYI

@hinthornw commented on GitHub (May 21, 2024): For all of the docs? What does your tsconfig look like? The change wasn't something for the actual StateGraph code, it was just fixing the docs FYI
Author
Owner

@claritise commented on GitHub (May 21, 2024):

Also getting the same error, here is my tsconfig, it's the standard T3 starter

{
  "compilerOptions": {
    /* Base Options: */
    "esModuleInterop": true,
    "skipLibCheck": true,
    "target": "es2022",
    "allowJs": true,
    "resolveJsonModule": true,
    "moduleDetection": "force",
    "isolatedModules": true,

    /* Strictness */
    "strict": true,
    "noUncheckedIndexedAccess": true,
    "checkJs": true,

    /* Bundled projects */
    "lib": ["dom", "dom.iterable", "ES2022"],
    "noEmit": true,
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "jsx": "preserve",
    "plugins": [{ "name": "next" }],
    "incremental": true,

    /* Path Aliases */
    "baseUrl": ".",
    "paths": {
      "~/*": ["./src/*"]
    }
  },
  "include": [
    ".eslintrc.cjs",
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx",
    "**/*.cjs",
    "**/*.js",
    ".next/types/**/*.ts"
  ],
  "exclude": ["node_modules"]
}
@claritise commented on GitHub (May 21, 2024): Also getting the same error, here is my tsconfig, it's the standard T3 starter ```js { "compilerOptions": { /* Base Options: */ "esModuleInterop": true, "skipLibCheck": true, "target": "es2022", "allowJs": true, "resolveJsonModule": true, "moduleDetection": "force", "isolatedModules": true, /* Strictness */ "strict": true, "noUncheckedIndexedAccess": true, "checkJs": true, /* Bundled projects */ "lib": ["dom", "dom.iterable", "ES2022"], "noEmit": true, "module": "ESNext", "moduleResolution": "Bundler", "jsx": "preserve", "plugins": [{ "name": "next" }], "incremental": true, /* Path Aliases */ "baseUrl": ".", "paths": { "~/*": ["./src/*"] } }, "include": [ ".eslintrc.cjs", "next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.cjs", "**/*.js", ".next/types/**/*.ts" ], "exclude": ["node_modules"] } ```
Author
Owner

@KeenanFernandes2000 commented on GitHub (May 23, 2024):

I'm still facing this issue on 0.0.19 version.

Idk if this is me only but most of the guides on the LangGraph documentation don't work with version 0.0.19.

@KeenanFernandes2000 commented on GitHub (May 23, 2024): > I'm still facing this issue on 0.0.19 version. Idk if this is me only but most of the guides on the LangGraph documentation don't work with version 0.0.19.
Author
Owner

@SilverLaius commented on GitHub (May 24, 2024):

FYI all the examples are broken and require a root reducer if you don't define a type since 0.0.13. Docs examples work with 0.0.12 and below since they do not add the type to StateGraph.
This is what broke it: https://github.com/langchain-ai/langgraphjs/commit/6866c22db61987ced4db19bf1c0b3e047cefceb6 @nfcampos
...Or well it was broken already before but this just made it mandatory pretty much to add the type to the StateGraph or it will require you to define some root value that is not documented anywhere. Previously it was extending Record<string, any> and you could get away with not defining it and doing whatever you wanted.

I guess you can still get away with adding the "untyped" Record as the state:
const graph = new StateGraph<Record<string, any>>({ channels: state})
But that is probably not what you want to have.

@SilverLaius commented on GitHub (May 24, 2024): FYI all the examples are broken and require a __root__ reducer if you don't define a type since 0.0.13. Docs examples work with 0.0.12 and below since they do not add the type to StateGraph. This is what broke it: https://github.com/langchain-ai/langgraphjs/commit/6866c22db61987ced4db19bf1c0b3e047cefceb6 @nfcampos ...Or well it was broken already before but this just made it mandatory pretty much to add the type to the StateGraph or it will require you to define some __root__ value that is not documented anywhere. Previously it was extending Record<string, any> and you could get away with not defining it and doing whatever you wanted. I guess you can still get away with adding the "untyped" Record as the state: `const graph = new StateGraph<Record<string, any>>({ channels: state})` But that is probably not what you want to have.
Author
Owner

@KeenanFernandes2000 commented on GitHub (May 25, 2024):

FYI all the examples are broken and require a root reducer if you don't define a type since 0.0.13. Docs examples work with 0.0.12 and below since they do not add the type to StateGraph. This is what broke it: 6866c22 @nfcampos ...Or well it was broken already before but this just made it mandatory pretty much to add the type to the StateGraph or it will require you to define some root value that is not documented anywhere. Previously it was extending Record<string, any> and you could get away with not defining it and doing whatever you wanted.

I guess you can still get away with adding the "untyped" Record as the state: const graph = new StateGraph<Record<string, any>>({ channels: state}) But that is probably not what you want to have.

Thanks for this, I actually had stuff running on version 0.0.12 but I couldn't get the checkpointer to work with the memory saver(which works in 0.0.13 and above from my testing). In short I wanted to convert one of my workflows to be session based as it would break if multiple executions were run. I guess ill have to wait till there's a proper solution.

@KeenanFernandes2000 commented on GitHub (May 25, 2024): > FYI all the examples are broken and require a **root** reducer if you don't define a type since 0.0.13. Docs examples work with 0.0.12 and below since they do not add the type to StateGraph. This is what broke it: [6866c22](https://github.com/langchain-ai/langgraphjs/commit/6866c22db61987ced4db19bf1c0b3e047cefceb6) @nfcampos ...Or well it was broken already before but this just made it mandatory pretty much to add the type to the StateGraph or it will require you to define some **root** value that is not documented anywhere. Previously it was extending Record<string, any> and you could get away with not defining it and doing whatever you wanted. > > I guess you can still get away with adding the "untyped" Record as the state: `const graph = new StateGraph<Record<string, any>>({ channels: state})` But that is probably not what you want to have. Thanks for this, I actually had stuff running on version 0.0.12 but I couldn't get the checkpointer to work with the memory saver(which works in 0.0.13 and above from my testing). In short I wanted to convert one of my workflows to be session based as it would break if multiple executions were run. I guess ill have to wait till there's a proper solution.
Author
Owner

@orthdron commented on GitHub (May 28, 2024):

I agree with the previous comments. It's quite challenging to develop with outdated documentation, especially when the core examples don't work. I understand this is an open-source project, but any help in updating the documentation would be greatly appreciated. Thank you!

@orthdron commented on GitHub (May 28, 2024): I agree with the previous comments. It's quite challenging to develop with outdated documentation, especially when the core examples don't work. I understand this is an open-source project, but any help in updating the documentation would be greatly appreciated. Thank you!
Author
Owner

@haisapan commented on GitHub (May 28, 2024):

yes the documentation is outdated, i tried to add root or use reducer but still got lots of error... I dare not use it as big break changes even have no documents..
image

@haisapan commented on GitHub (May 28, 2024): yes the documentation is outdated, i tried to add __root__ or use reducer but still got lots of error... I dare not use it as big break changes even have no documents.. <img width="732" alt="image" src="https://github.com/langchain-ai/langgraphjs/assets/1772696/0d98216c-ec7e-44c9-aae8-19fc74ddad5e">
Author
Owner

@FelixGirard commented on GitHub (May 28, 2024):

I'm new to Langchain and had some trouble figuring out why it wasn't working.
The documentation is really important.
From the commit and the tests I was able to make it work, I still don't know what type to put instead of any for the steps.


type StateSchema = {
  input: string | null;
  agentOutcome: string | null;
  steps: Array<string>;
};

const schema = {
  input: null,
  agentOutcome: null,
  steps: {
    value: (x: any, y: any) => x.concat(y),
    default: () => [],
  },
};

const graph = new StateGraph<StateSchema>({
  channels: schema, 
});
@FelixGirard commented on GitHub (May 28, 2024): I'm new to Langchain and had some trouble figuring out why it wasn't working. The documentation is really important. From the commit and the tests I was able to make it work, I still don't know what type to put instead of `any` for the steps. ````ts type StateSchema = { input: string | null; agentOutcome: string | null; steps: Array<string>; }; const schema = { input: null, agentOutcome: null, steps: { value: (x: any, y: any) => x.concat(y), default: () => [], }, }; const graph = new StateGraph<StateSchema>({ channels: schema, });
Author
Owner

@KeenanFernandes2000 commented on GitHub (May 30, 2024):

I'm new to Langchain and had some trouble figuring out why it wasn't working.
The documentation is really important.
From the commit and the tests I was able to make it work, I still don't know what type to put instead of any for the steps.


type StateSchema = {
  input: string | null;
  agentOutcome: string | null;
  steps: Array<string>;
};

const schema = {
  input: null,
  agentOutcome: null,
  steps: {
    value: (x: any, y: any) => x.concat(y),
    default: () => [],
  },
};

const graph = new StateGraph<StateSchema>({
  channels: schema, 
});

By any chance did you happen to work with memory saver and check-pointers?

@KeenanFernandes2000 commented on GitHub (May 30, 2024): > I'm new to Langchain and had some trouble figuring out why it wasn't working. > The documentation is really important. > From the commit and the tests I was able to make it work, I still don't know what type to put instead of `any` for the steps. > ````ts > > type StateSchema = { > input: string | null; > agentOutcome: string | null; > steps: Array<string>; > }; > > const schema = { > input: null, > agentOutcome: null, > steps: { > value: (x: any, y: any) => x.concat(y), > default: () => [], > }, > }; > > const graph = new StateGraph<StateSchema>({ > channels: schema, > }); By any chance did you happen to work with memory saver and check-pointers?
Author
Owner

@FelixGirard commented on GitHub (May 30, 2024):

I'm new to Langchain and had some trouble figuring out why it wasn't working.
The documentation is really important.
From the commit and the tests I was able to make it work, I still don't know what type to put instead of any for the steps.

type StateSchema = {
  input: string | null;
  agentOutcome: string | null;
  steps: Array<string>;
};

const schema = {
  input: null,
  agentOutcome: null,
  steps: {
    value: (x: any, y: any) => x.concat(y),
    default: () => [],
  },
};

const graph = new StateGraph<StateSchema>({
  channels: schema, 
});

By any chance did you happen to work with memory saver and check-pointers?

I haven't no, any specific error you are getting on that guide?

@FelixGirard commented on GitHub (May 30, 2024): > > I'm new to Langchain and had some trouble figuring out why it wasn't working. > > The documentation is really important. > > From the commit and the tests I was able to make it work, I still don't know what type to put instead of `any` for the steps. > > ```ts > > type StateSchema = { > > input: string | null; > > agentOutcome: string | null; > > steps: Array<string>; > > }; > > > > const schema = { > > input: null, > > agentOutcome: null, > > steps: { > > value: (x: any, y: any) => x.concat(y), > > default: () => [], > > }, > > }; > > > > const graph = new StateGraph<StateSchema>({ > > channels: schema, > > }); > > ``` > > By any chance did you happen to work with memory saver and check-pointers? I haven't no, any specific error you are getting on that guide?
Author
Owner

@hinthornw commented on GitHub (May 31, 2024):

Thanks for flagging this, everyone, and thanks for your patience. As a JS noob I suppose it was a bad idea to just write the docs in JS rather than typescript - clearly typing is more commonly enforced here than in python

I went through all the tutorials in the docs, all the how-tos, and the README and rewrote them, compiled with TSC and ran in typescript with no complaints. Hopefully this resolves this issue. Will keep this issue open another day or two to let others push back since obviously I may have missed some things, but hopefully it will be less painful for everyone writing typescript to get started moving forward.

Big thank you to all on this thread and elsewhere for raising this issue and for bearing with us!

@hinthornw commented on GitHub (May 31, 2024): Thanks for flagging this, everyone, and thanks for your patience. As a JS noob I suppose it was a bad idea to just write the docs in JS rather than typescript - clearly typing is more commonly enforced here than in python I went through all the tutorials in the docs, all the how-tos, and the README and rewrote them, compiled with TSC and ran in typescript with no complaints. Hopefully this resolves this issue. Will keep this issue open another day or two to let others push back since obviously I may have missed some things, but hopefully it will be less painful for everyone writing typescript to get started moving forward. Big thank you to all on this thread and elsewhere for raising this issue and for bearing with us!
Author
Owner

@vanb commented on GitHub (Jun 9, 2024):

Thanks for working on the docs @hinthornw. I'm still receiving a type error even with the "quick start" example.

Argument of type '"agent"' is not assignable to parameter of type '"__end__" | "__start__"'.

image

I also received an error when adding the tools node, but fixed that by typing it as new ToolNode<BaseMessage[]>(tools)

@vanb commented on GitHub (Jun 9, 2024): Thanks for working on the docs @hinthornw. I'm still receiving a type error even with the ["quick start" example](https://langchain-ai.github.io/langgraphjs/). `Argument of type '"agent"' is not assignable to parameter of type '"__end__" | "__start__"'.` ![image](https://github.com/langchain-ai/langgraphjs/assets/127372/dffe7cd3-dd41-4bc5-a12c-557fdb6c2b95) I also received an error when adding the tools node, but fixed that by typing it as `new ToolNode<BaseMessage[]>(tools)`
Author
Owner

@hinthornw commented on GitHub (Jun 12, 2024):

🙈 - rewrote. Thanks for reporting the issue vanb!

@hinthornw commented on GitHub (Jun 12, 2024): 🙈 - rewrote. Thanks for reporting the issue vanb!
Author
Owner

@prashantbhudwal commented on GitHub (Feb 22, 2025):

Error here in the example:

https://langchain-ai.github.io/langgraphjs/concepts/low_level/#multiple-schemas

Image

@prashantbhudwal commented on GitHub (Feb 22, 2025): Error here in the example: [¶](https://langchain-ai.github.io/langgraphjs/concepts/low_level/#annotation) https://langchain-ai.github.io/langgraphjs/concepts/low_level/#multiple-schemas ![Image](https://github.com/user-attachments/assets/19afd600-d57e-458f-9d16-4548ae0a514b)
Author
Owner

@benjamincburns commented on GitHub (Feb 23, 2025):

Ah, thanks for that @prashantbhudwal - I'll reopen.

@benjamincburns commented on GitHub (Feb 23, 2025): Ah, thanks for that @prashantbhudwal - I'll reopen.
Author
Owner

@benjamincburns commented on GitHub (Feb 24, 2025):

Turns out this is a bug in the type constraints, not in the docs. Will fix.

@benjamincburns commented on GitHub (Feb 24, 2025): Turns out this is a bug in the type constraints, not in the docs. Will fix.
Author
Owner

@benjamincburns commented on GitHub (Feb 24, 2025):

For the moment it seems that we may have painted ourselves into a corner on this one. I'll update the docs to make the example work, but unfortunately it can't be done in the current code using inferred type parameters.

The working example looks like this:

import { Annotation, START, StateGraph, StateType, UpdateType } from "@langchain/langgraph";

const InputStateAnnotation = Annotation.Root({
  user_input: Annotation<string>,
});

const OutputStateAnnotation = Annotation.Root({
  graph_output: Annotation<string>,
});

const OverallStateAnnotation = Annotation.Root({
  foo: Annotation<string>,
  bar: Annotation<string>,
  user_input: Annotation<string>,
  graph_output: Annotation<string>,
});

const node1 = async (state: typeof InputStateAnnotation.State) => {
  // Write to OverallStateAnnotation
  return { foo: state.user_input + " name" };
};

const node2 = async (state: typeof OverallStateAnnotation.State) => {
  // Read from OverallStateAnnotation, write to OverallStateAnnotation
  return { bar: state.foo + " is" };
};

const node3 = async (state: typeof OverallStateAnnotation.State) => {
  // Read from OverallStateAnnotation, write to OutputStateAnnotation
  return { graph_output: state.bar + " Lance" };
};

const graph = new StateGraph<
  typeof OverallStateAnnotation["spec"],
  StateType<typeof OverallStateAnnotation["spec"]>,
  UpdateType<typeof OutputStateAnnotation["spec"]>,
  typeof START,
  typeof InputStateAnnotation["spec"],
  typeof OutputStateAnnotation["spec"]
>({
  input: InputStateAnnotation,
  output: OutputStateAnnotation,
  stateSchema: OverallStateAnnotation,
})
  .addNode("node1", node1)
  .addNode("node2", node2)
  .addNode("node3", node3)
  .addEdge("__start__", "node1")
  .addEdge("node1", "node2")
  .addEdge("node2", "node3")
  .compile();

await graph.invoke({ user_input: "My" });
@benjamincburns commented on GitHub (Feb 24, 2025): For the moment it seems that we may have painted ourselves into a corner on this one. I'll update the docs to make the example work, but unfortunately it can't be done in the current code using inferred type parameters. The working example looks like this: ```typescript: import { Annotation, START, StateGraph, StateType, UpdateType } from "@langchain/langgraph"; const InputStateAnnotation = Annotation.Root({ user_input: Annotation<string>, }); const OutputStateAnnotation = Annotation.Root({ graph_output: Annotation<string>, }); const OverallStateAnnotation = Annotation.Root({ foo: Annotation<string>, bar: Annotation<string>, user_input: Annotation<string>, graph_output: Annotation<string>, }); const node1 = async (state: typeof InputStateAnnotation.State) => { // Write to OverallStateAnnotation return { foo: state.user_input + " name" }; }; const node2 = async (state: typeof OverallStateAnnotation.State) => { // Read from OverallStateAnnotation, write to OverallStateAnnotation return { bar: state.foo + " is" }; }; const node3 = async (state: typeof OverallStateAnnotation.State) => { // Read from OverallStateAnnotation, write to OutputStateAnnotation return { graph_output: state.bar + " Lance" }; }; const graph = new StateGraph< typeof OverallStateAnnotation["spec"], StateType<typeof OverallStateAnnotation["spec"]>, UpdateType<typeof OutputStateAnnotation["spec"]>, typeof START, typeof InputStateAnnotation["spec"], typeof OutputStateAnnotation["spec"] >({ input: InputStateAnnotation, output: OutputStateAnnotation, stateSchema: OverallStateAnnotation, }) .addNode("node1", node1) .addNode("node2", node2) .addNode("node3", node3) .addEdge("__start__", "node1") .addEdge("node1", "node2") .addEdge("node2", "node3") .compile(); await graph.invoke({ user_input: "My" }); ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#26