yunabe / tslab

Interactive JavaScript and TypeScript programming with Jupyter
Apache License 2.0
740 stars 45 forks source link

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

Open indicava opened 1 month ago

indicava commented 1 month ago

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?