fix(massimo-cli): declare frontend setter exports in generated types#172
Open
mirko-pira wants to merge 1 commit into
Open
fix(massimo-cli): declare frontend setter exports in generated types#172mirko-pira wants to merge 1 commit into
mirko-pira wants to merge 1 commit into
Conversation
The frontend implementation file exports setBaseUrl, setDefaultHeaders
and setDefaultFetchParams as module-level named exports, but the
generated <name>-types.d.ts never declared them. Consumers whose
tooling resolves types from the .d.ts (e.g. package.json "types"
mappings) got TS2305 errors on
`import { setDefaultHeaders } from './client'` even though the
symbols exist at runtime.
Emit matching `export declare const` statements in the types file,
typed via the client interface's own members so they can never drift
from the interface declarations.
Signed-off-by: Mirko Pira <mp@mirkodev.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(massimo-cli): declare frontend setter exports in generated types
Problem
For frontend clients (
--frontend), the generated implementation file exports three module-level functions:but the generated
<name>-types.d.tsnever declares them. They only appear as methods on the client interface (setBaseUrl(newUrl: string): void;etc.), which does not describe the module's named exports.Any consumer whose tooling resolves types from the
.d.ts— for example a package that ships the generated client with a"types"field pointing at<name>-types.d.ts— getsTS2305: Module has no exported member 'setDefaultHeaders'oneven though the symbol exists at runtime. Until now we have been post-processing the generated
.d.tswithsedto re-add the three declarations after every regeneration.Reproduction
api/api.mtsexportssetBaseUrl,setDefaultHeaders,setDefaultFetchParams;api/api-types.d.tscontains no top-level declaration for any of them. Same for--language js(the JSDoc@typeannotations reference the interface members, but a.d.ts-only consumer still sees no named exports).Fix
generateTypesFromOpenAPIinpackages/massimo-cli/lib/frontend-openapi-generator.jsnow emits, right after the client interface:The declarations are typed via the interface's own members (same pattern the JS implementation already uses in its JSDoc
@typeannotations), so they can never drift from the interface.Tests
test/frontend-openapi.test.js: extended thefactoryTypetemplate in the base test to pin the exact placement of the three declarations, and added explicit assertions in "generate frontend client from path" and in the watt-config test.test/cli-openapi-status-code-204.test.js: updated the expected.d.tstemplate to the new output.Full
massimo-clisuite: 136/136 passing (node --test test/*.test.js),tsdandeslintclean.