Skip to content

Fix WithContext to exclude string members (#98) - #219

Open
cochinescu wants to merge 1 commit into
google:mainfrom
cochinescu:fix-98-withcontext
Open

Fix WithContext to exclude string members (#98)#219
cochinescu wants to merge 1 commit into
google:mainfrom
cochinescu:fix-98-withcontext

Conversation

@cochinescu

Copy link
Copy Markdown
Contributor

Every generated schema type is a union that includes string (e.g. Organization = OrganizationLeaf | ... | string). WithContext<T> was emitted as T & { "@context": ... }, which left a meaningless string & { "@context" } branch in the result — exactly the "cannot intersect string and object" defect reported in #98.

WithContext is only ever applied to a top-level object, so strip the non-object members: emit Exclude<T, string> & { "@context": ... }. This matches the maintainer-suggested fix and the factory's own comment.

Adds a generator baseline regression test asserting the emitted shape, a consumer-level assertion that WithContext<Thing> has no string member, and regenerates the affected baseline snapshots.

Fixes #98

Every generated schema type is a union that includes `string` (e.g.
`Organization = OrganizationLeaf | ... | string`). `WithContext<T>` was
emitted as `T & { "@context": ... }`, which left a meaningless
`string & { "@context" }` branch in the result — exactly the
"cannot intersect string and object" defect reported in google#98.

WithContext is only ever applied to a top-level object, so strip the
non-object members: emit `Exclude<T, string> & { "@context": ... }`.
This matches the maintainer-suggested fix and the factory's own comment.

Adds a generator baseline regression test asserting the emitted shape,
a consumer-level assertion that `WithContext<Thing>` has no string member,
and regenerates the affected baseline snapshots.

Fixes google#98
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.

The WithContext type is invalid

1 participant