document tsconfig `lib`/`target` requirements

Abierto
#112 9 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 5 días

Nadie ha tomado este issue todavía.

  • #246 de @ting-hong-shieh — cerrado sin fusionar

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
typescript
Área
api

Línea de trabajo

Comienza localizando la definición del tipo RpcStub y las declaraciones genéricas de newWebSocketRpcSession y newHttpBatchRpcSession. Reproduce el problema con el ejemplo de TypeScript y verifica después que los tipos de retorno de objetos como ApiMessage se conserven y que las propiedades no válidas sean rechazadas por la comprobación de tipos.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

documentation

Description

When using newWebSocketRpcSession or newHttpBatchRpcSession with a TypeScript generic parameter, the RpcStub<T> type preserves primitive return types (string, number, boolean) but fails to preserve object/interface return types, returning any instead.

Minimal Reproducible Example

import { newWebSocketRpcSession, type RpcStub } from 'capnweb';

// Define types
type ApiMessage = { message: string; timestamp: string };

// Define API interface
interface MyApi {
  getPrimitive(): Promise<string>;           // Returns primitive
  getObject(): Promise<ApiMessage>;          // Returns object
  hello(name: string): Promise<ApiMessage>;  // Returns object
}

// Create client
const apiStub = newWebSocketRpcSession<MyApi>('wss://example.com/api');

// Primitives work correctly ✅
const primitive = await apiStub.getPrimitive();
//    ^? Type is 'string' ✅

// Objects return 'any' ❌
const object = await apiStub.getObject();
//    ^? Type is 'any' ❌

const helloResult = await apiStub.hello('world');
//    ^? Type is 'any' ❌

Expected Behavior

All method return types should be preserved, regardless of whether they're primitives or objects:

const primitive = await apiStub.getPrimitive();
//    ^? string ✅

const object = await apiStub.getObject();
//    ^? Should be: ApiMessage

const helloResult = await apiStub.hello('world');
//    ^? Should be: ApiMessage

Actual Behavior

Only primitive return types are preserved. Object/interface return types become any:

const apiStub: RpcStub<MyApi> = newWebSocketRpcSession<MyApi>('wss://example.com/api');
//    ^? Correctly shows: RpcStub<MyApi>

const primitive = await apiStub.getPrimitive();
//    ^? string ✅ Works!

const object = await apiStub.getObject();
//    ^? any ❌ Should be ApiMessage

const helloResult = await apiStub.hello('world');
//    ^? any ❌ Should be ApiMessage

// No type checking for objects
console.log(helloResult.anythingGoes); // No error

Root Cause

The RpcStub<T> type definition appears to handle primitives correctly but wraps object return types in complex proxy types (for promise pipelining support) that resolve to any instead of the original type.

Workaround

Manually cast each result:

const helloResult = await apiStub.hello('world') as ApiMessage;
//    ^? Now correctly typed as: ApiMessage ✅

Environment

  • capnweb version: 0.2.0
  • TypeScript version: 5.8.3
  • Node version: 22.15.1
Lenguaje dominante
TypeScript
Estrellas
4k
Forks
150
Merge medio
3 d 12 h
PR fusionados (30 d)
2

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de cloudflare/capnweb

Todos los issues de cloudflare/capnweb

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.