You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b5f4b3d
Browse filesBrowse the repository at this point in the historyBrowse files
fix(sdk-codegen): make run_inline_query response type generic (#1730) (#1759)
## What
`run_inline_query` is hardcoded to return `SDKResponse<string, ...>`,
but when `result_format` is `'json'` the transport layer actually
deserializes the body into an object/array. Since `value` is typed as
`string`, callers have no valid TypeScript path to the real data and are
forced into `as unknown as T` casts, which defeats type safety entirely.
Looker's OpenAPI spec declares a single `200: { schema: { type: string }
}` response for this endpoint with no per-`result_format` breakdown, so
the generator can't derive the real shape per format automatically. This
PR makes `run_inline_query` generic instead:
```ts
async run_inline_query<T = string>(
request: IRequestRunInlineQuery,
options?: Partial<ITransportSettings>
): Promise<SDKResponse<T, IError | IValidationError>>
```
Callers who know their query's shape (they always do — they specify
model/view/fields) can now write:
```ts
const response = await sdk.run_inline_query<StoreProduct[]>(req);
if (response.ok) {
response.value; // StoreProduct[] — no cast
}
```
## Backward compatibility — this is opt-in, no existing consumers break
- `<T = string>` has a **default type argument**. Any existing call site
that doesn't supply a generic (`sdk.run_inline_query(request)`) resolves
`T` to `string`, exactly as before — no change in inferred type, no
change in behavior.
- Generic type parameters are compile-time only and erased by the
TypeScript compiler; the emitted JavaScript for `this.post(...)` is
identical regardless of `T`. No runtime behavior changes.
- The method signature (arguments, arity, return shape) is otherwise
untouched.
- Verified: `yarn build` type-checks the full monorepo against the new
signature with zero errors, and reverting only the implementation
(leaving the generic interface) reliably produces a type error —
confirming the generic threads correctly end-to-end and that plain,
non-generic call sites are unaffected.
## Scope
This is scoped to `run_inline_query` only, per the linked issue. The
same `result_format`-driven typing problem exists on a few sibling
methods (`run_query`, `run_look`, `run_url_encoded_query`,
`run_sql_query`) that weren't touched here to keep this PR minimal and
reviewable. Happy to circle back and apply the same generic-default
pattern to those once this approach is confirmed to be the right one.
## Changes
- `packages/sdk-codegen/src/typescript.gen.ts`: generator now emits `<T
= string>` for methods special-cased as "format-dependent string"
responses (currently just `run_inline_query`).
- `packages/sdk/src/4.0/methods.ts`, `methodsInterface.ts`, `funcs.ts`:
regenerated output for `run_inline_query` reflecting the generic.
Fixes#1703
## Test plan
- [x] `yarn build` passes cleanly across all 21 packages
- [x] Full `sdk` / `sdk-codegen` / `sdk-rtl` jest suites pass (only
pre-existing, unrelated failures remain — 2 tests requiring a live
`looker.ini`, confirmed to fail identically on `main`)
- [x] Manually verified (via a temporary local test, not included in
this PR) that a caller can do `sdk.run_inline_query<MyType[]>(request)`
and get a fully typed `response.value` with no cast, and that omitting
the generic still defaults to `string`
- [x] Confirmed the fix is load-bearing by reverting just the
`methods.ts` implementation and re-running `tsc` — it immediately fails
type-checking against the generic interface, proving the change is
meaningful
Co-authored-by: Marc <marc@marcswilson.com>
0 commit comments