Skip to content

Does tslab enforce type checking even when using the JavaScript kernel? #103

Description

@indicava

Running the following code (taken from the notebooks provided in the tutorials for LangGraphJS):

import { Annotation } from "@langchain/langgraph"

const PlanExecuteState = Annotation.Root({
	input: Annotation({
		reducer: (x, y) => y ?? x ?? "",
	}),
	plan: Annotation({
		reducer: (x, y) => y ?? x ?? [],
	}),
	pastSteps: Annotation({
		reducer: (x, y) => x.concat(y),
	}),
	response: Annotation({
		reducer: (x, y) => y ?? x,
	}),
})

With a JavaScript kernel, on a new notebook, fails with this error:

11:24 - Property 'concat' does not exist on type 'unknown'.

It appears Type Checking is somehow still active even with the JavaScript kernel selected. Changing the code like this and choosing the TypeScript kernel, works:

import { Annotation } from "@langchain/langgraph"

const PlanExecuteState = Annotation.Root({
	input: Annotation({
		reducer: (x, y) => y ?? x ?? "",
	}),
	plan: Annotation({
		reducer: (x, y) => y ?? x ?? [],
	}),
	pastSteps: Annotation({
		reducer: (x: any, y) => x.concat(y),
	}),
	response: Annotation({
		reducer: (x, y) => y ?? x,
	}),
})

Furthermore, running the first (un-typed) code snippet in a regular node ".js" file runs fine with no runtime errors.

Lastly, this happens only when importing the Annotation class, for example, this code works perfectly fine in a notebook with JavaScript kernel:

const y = {
    a: "test",
    b: (x, y) => x.concat(y),
}

y.b(y.a, y.a)

What am I missing?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions