Skip to content

sdks/ts: replace any with proper types in SDK core#2857

Merged
vigoo merged 3 commits intomainfrom
fix/sdks-ts-type-improvements
Mar 18, 2026
Merged

sdks/ts: replace any with proper types in SDK core#2857
vigoo merged 3 commits intomainfrom
fix/sdks-ts-type-improvements

Conversation

@Myestery
Copy link
Contributor

@Myestery Myestery commented Mar 2, 2026

Summary

  • Replace any types with unknown, generics, and proper type constraints across ~15 SDK files
  • Use Reflect.construct for safe class instantiation in the decorator
  • Use Object.assign pattern for typed function objects in client generation
  • Add generic wrappers for deserialize/deserializeDataValue to maintain public API types while using unknown internally
  • Extract MethodKeys<T> helper type for cleaner Client<T> definition
  • Add MutableAgentStatics type to avoid (ctor as any).get = ... pattern

Context

Split from #2845 based on reviewer feedback. This PR focuses only on SDK type improvements, excluding:

Test plan

  • tsc --noEmit passes
  • All 163 tests pass across 11 test files
  • Rollup build succeeds

@github-actions
Copy link

github-actions bot commented Mar 2, 2026

✅ All contributors have signed the CLA.
Posted by the CLA Assistant Lite bot.

Replace `any` types with `unknown`, generics, and proper type
constraints across the SDK. Uses Reflect.construct for safe
instantiation, Object.assign for typed function objects, and
generic wrappers for deserialize functions.
@Myestery Myestery force-pushed the fix/sdks-ts-type-improvements branch from 66d9fd4 to 4dd8861 Compare March 9, 2026 22:24
*/
export type OperationErrors<T extends Operation<any, any, any>[]> = {
[K in keyof T]: T[K] extends Operation<any, any, infer Err> ? Err : never;
export type OperationErrors<T extends Operation<unknown, unknown, unknown>[]> = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't give any extra safety, but I am not totally against this change

}

function assertErrorInstanceOf<T, C extends abstract new (..._: any) => any>(
function assertErrorInstanceOf<T, C extends abstract new (..._: unknown[]) => unknown>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again not much value add. It doesn't provide extra safety, but not "against" this change just because it kind of look better than previous version

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any is not unknown. Sometimes any does makes more sense.

}

function unsupportedWithHint(kind: string, hint: string): Handler<any> {
function unsupportedWithHint<K extends TsType['kind']>(kind: string, hint: string): Handler<K> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


const nameAndElementValues = serializeMultimodalToDataValue(tsValue, multiModalTypeInfo);
const nameAndElementValues = serializeMultimodalToDataValue(
tsValue as Record<string, unknown>[],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No extra safety, as far as I see.


// type mismatch in tsValue when converting from TS to WIT
export function typeMismatchInSerialize(tsValue: any, expectedType: string): string {
export function typeMismatchInSerialize(tsValue: unknown, expectedType: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you think about this, it's not unknown. its any

type AllOptional<T extends readonly unknown[], I extends any[] = []> = T extends readonly [
any,
type AllOptional<T extends readonly unknown[], I extends unknown[] = []> = T extends readonly [
unknown,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again no much safety introduction.
But this version is not harming. Hence approving

@afsalthaj
Copy link
Contributor

afsalthaj commented Mar 16, 2026

I would recommend not changing much on any part of SDK going forward. Our SDK is not a typical TS application. It's a machinary which has the flexibility to do "any"thing to make a real TS application in agent looks better.

That said, thanks for making some parts of the code look better.

get?: unknown;
newPhantom?: unknown;
getPhantom?: unknown;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just delaying the "guilt" :D Unless I don't understand how it can make it safe. I trust it doesn't harm though

@vigoo
Copy link
Contributor

vigoo commented Mar 16, 2026

Lot of conflicts due to my optimisations. Let's resolve them, but make sure the optimizations are not reverted

…ovements

# Conflicts:
#	sdks/ts/packages/golem-ts-sdk/src/decorators/agent.ts
#	sdks/ts/packages/golem-ts-sdk/src/internal/clientGeneration.ts
#	sdks/ts/packages/golem-ts-sdk/src/internal/mapping/values/Value.ts
#	sdks/ts/packages/golem-ts-sdk/src/internal/mapping/values/WitValue.ts
#	sdks/ts/packages/golem-ts-sdk/src/internal/mapping/values/dataValue.ts
#	sdks/ts/packages/golem-ts-sdk/src/internal/mapping/values/deserializer.ts
#	sdks/ts/packages/golem-ts-sdk/src/internal/resolvedAgent.ts
@vigoo vigoo merged commit 5198321 into main Mar 18, 2026
29 checks passed
@vigoo vigoo deleted the fix/sdks-ts-type-improvements branch March 18, 2026 07:31
@github-actions github-actions bot locked and limited conversation to collaborators Mar 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants