Skip to content

Commit

Permalink
core(patch): Allow generic typing for context var methods (#6978)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 authored Oct 13, 2024
1 parent f075b08 commit b627486
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions langchain-core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ AsyncLocalStorageProviderSingleton.initializeGlobalInstance(
* @param value The value to set.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function setContextVariable(name: PropertyKey, value: any): void {
export function setContextVariable<T>(name: PropertyKey, value: T): void {
const runTree = AsyncLocalStorageProviderSingleton.getInstance().getStore();
const contextVars = { ...runTree?.[_CONTEXT_VARIABLES_KEY] };
contextVars[name] = value;
Expand Down Expand Up @@ -125,7 +125,7 @@ export function setContextVariable(name: PropertyKey, value: any): void {
* @param name The name of the context variable.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function getContextVariable(name: PropertyKey): any {
export function getContextVariable<T = any>(name: PropertyKey): T | undefined {
const runTree = AsyncLocalStorageProviderSingleton.getInstance().getStore();
return runTree?.[_CONTEXT_VARIABLES_KEY]?.[name];
}

0 comments on commit b627486

Please sign in to comment.