Skip to content

Conversation

@izaakschroeder
Copy link

@izaakschroeder izaakschroeder commented Dec 30, 2025

NOTE: There are not many significant updates here – the bulk of the diff is regenerating snapshots and examples. The core changes are added a little code to generate | undefined on the built types and adding | undefined to the existing runtime template types. As far as I can tell there is no usage of e.g. 'foo' in obj ? obj.foo : ... but instead obj.foo ?? ..., the latter of which is totally fine with these changes.

TODO:

  • Add tests

Previously types generated look like { foo?: string }, now they look like { foo?: string | undefined }.

Before:

error TS2375: Type '{ body: unknown; fetch: typeof fetch; headers: Headers; serializedBody: undefined; path?: Record<string, unknown> | undefined; query?: Record<string, unknown> | undefined; security?: ReadonlyArray<Auth> | undefined; ... 28 more ...; sseMaxRetryDelay?: number | undefined | undefined; }' is not assignable to type 'ReqInit' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
  Type '{ body: unknown; fetch: typeof fetch; headers: Headers; serializedBody: undefined; path?: Record<string, unknown> | undefined; query?: Record<string, unknown> | undefined; security?: ReadonlyArray<Auth> | undefined; ... 28 more ...; sseMaxRetryDelay?: number | undefined | undefined; }' is not assignable to type 'Omit<RequestInit, "body" | "headers">' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
    Types of property 'method' are incompatible.
      Type 'string | undefined' is not assignable to type 'string'.
        Type 'undefined' is not assignable to type 'string'.

TS2379: Argument of type '{ body: BodyInit | null | undefined; headers: Record<string, string>; method: "CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE"; ... 33 more ...; sseMaxRetryDelay?: number | undefined; }' is not assignable to parameter of type 'ServerSentEventsOptions<unknown>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
  Type '{ body: BodyInit | null | undefined; headers: Record<string, string>; method: "CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE"; ... 33 more ...; sseMaxRetryDelay?: number | undefined; }' is not assignable to type 'Omit<RequestInit, "method">' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
    Types of property 'body' are incompatible.
      Type 'BodyInit | null | undefined' is not assignable to type 'BodyInit | null'.
        Type 'undefined' is not assignable to type 'BodyInit | null'.

TS18048: 'security' is possibly 'undefined'.
../../../../../../../private/var/folders/v6/v4_1_hhd2rdf6fbrnbs_jtf40000gn/T/ff8e6f7ea59a6a382f6b6023959fd7e7/client/utils.gen.ts(167,10): error TS2379: Argument of type '{ baseUrl: string; path: Record<string, unknown> | undefined; query: Record<string, unknown> | undefined; querySerializer: QuerySerializer; url: string; }' is not assignable to parameter of type '{ baseUrl?: string; path?: Record<string, unknown>; query?: Record<string, unknown>; querySerializer: QuerySerializer; url: string; }' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
  Types of property 'path' are incompatible.
    Type 'Record<string, unknown> | undefined' is not assignable to type 'Record<string, unknown>'.
      Type 'undefined' is not assignable to type 'Record<string, unknown>'.

TS2375: Type '{ body: BodyInit | null | undefined; headers: Headers; signal: AbortSignal; cache?: RequestCache; credentials?: RequestCredentials; integrity?: string; ... 9 more ...; serializedBody?: RequestInit["body"] | undefined; }' is not assignable to type 'RequestInit' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
  Types of property 'body' are incompatible.
    Type 'BodyInit | null | undefined' is not assignable to type 'BodyInit | null'.
      Type 'undefined' is not assignable to type 'BodyInit | null'.
image

Refs: #2236

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@codesandbox
Copy link

codesandbox bot commented Dec 30, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@changeset-bot
Copy link

changeset-bot bot commented Dec 30, 2025

🦋 Changeset detected

Latest commit: f06d1fc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hey-api/openapi-ts Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Dec 30, 2025

@izaakschroeder is attempting to deploy a commit to the Hey API Team on Vercel.

A member of the Team first needs to authorize it.

@codecov
Copy link

codecov bot commented Dec 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 32.82%. Comparing base (929bab9) to head (f06d1fc).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3157      +/-   ##
==========================================
- Coverage   32.83%   32.82%   -0.01%     
==========================================
  Files         430      430              
  Lines       34126    34134       +8     
  Branches     2157     2157              
==========================================
  Hits        11204    11204              
- Misses      22894    22902       +8     
  Partials       28       28              
Flag Coverage Δ
unittests 32.82% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@izaakschroeder izaakschroeder force-pushed the exact-optional-properties branch from 4bed041 to 15d0324 Compare December 30, 2025 09:43
@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 30, 2025

Open in StackBlitz

npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/codegen-core@3157
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/nuxt@3157
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/openapi-ts@3157
npm i https://pkg.pr.new/hey-api/openapi-ts/@hey-api/vite-plugin@3157

commit: f06d1fc

@izaakschroeder izaakschroeder force-pushed the exact-optional-properties branch 18 times, most recently from 0d4e035 to 938a565 Compare December 31, 2025 05:40
@izaakschroeder izaakschroeder force-pushed the exact-optional-properties branch from 938a565 to f06d1fc Compare December 31, 2025 06:04
@mrlubos
Copy link
Member

mrlubos commented Jan 2, 2026

I don't think this would help us long-term because it doesn't prevent from writing more non-compliant code. I'm not sure what the ideal fix here is, is skipping the rule for the offending files not an option?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants