Repository navigation
fix(vite): type generated refs by their picked exports - #20
Open
everton-dgn wants to merge 1 commit into
Open
everton-dgn wants to merge 1 commit into
everton-dgn wants to merge 1 commit into
Conversation
Type lazy and eager refs with Pick<M, Extract<P, keyof M>>, using the names in ref.pick without the synthetic $css. Refs with no names left use a generic type. Picked names stay accessible when the module is any. Compile generated declarations with small consumer files to check that mocks returning only default typecheck and reads outside the pick fail. Cover untyped JavaScript routes with code splitting on and off.
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.
With
fileRoutes({ types: true }), every ref is typed as the full source module even though it selects only some exports. For a route like this:The generated type rejects
routes[0].$component.import = async () => ({ default: () => null })becauserouteis missing. It also acceptsroutes[0].$$route.require().default, which is absent at runtime.Each ref is now typed as
Pick<M, Extract<P, keyof M>>, whereMis the source module andPcomes fromref.pickwithout the synthetic$cssname. This covers lazy and eager refs, including server pages. The$HEADfallback picksGET. Picked names remain accessible asanywhen TypeScript has no types for a JavaScript route. Markdown modules keep generic refs; refs with no names left after filtering also use the generic type.The tests compile generated declarations with small consumer files. Component mocks returning only
defaulttypecheck, and reads outside the pick fail in both manifest views. They also cover.jsand.jsxroutes withoutallowJs, with code splitting on and off. The new cases failed before their fixes and now pass.pnpm testandpnpm exec tsc --noEmitpass.The only shared file with #17 is
test/vite.spec.ts, and its diff applies cleanly on top. With #17, the server loads a server page's module whole while the client still picksdefault; the narrower type holds for both.