feat(types): add more precise typing for known query types to match known as types#21863
Conversation
sapphi-red
left a comment
There was a problem hiding this comment.
I think we can have this.
Would you add type tests like these?
I created a new file |
|
Friendly ping here, anything else I could do on my side to help move this along? cc @sapphi-red |
|
/ecosystem-ci run |
@vitejs/plugin-legacy
vite
commit: |
|
📝 Ran ecosystem CI on
✅ analogjs, sveltekit, react-router, qwik, laravel, storybook, quasar, module-federation, nuxt, vite-plugin-rsc, vite-plugin-vue, vite-plugin-pwa, vitepress, vite-environment-examples, vite-plugin-react, waku, vite-setup-catalogue, vuepress, vite-plugin-svelte, vike, unocss |
…nvs) Vite reports its inputs/outputs/envs to the `vp` runner via `@voidzero-dev/vite-task-client`, so `vp build` no longer needs a hand-synthesized cache config. - Bump vite-task git deps to c44d7c33 (runner-aware IPC server/client + embedded napi addon); regenerate run-config.ts for the new task-config types. - Point the vite behind vp build/vp dev to latest vitejs/vite (c13a37b53), which carries the vite-task-client integration. vite lists vite-task-client in devDependencies, so it is bundled into vite's output (and thus into core) the same way as vite's other bundled deps (cac, esbuild, ...) — no extra dependency or build wiring needed. - Work around an upstream vite dts bug (vitejs/vite#21863): `node/index.ts` re-exports `KnownQueryTypeMap` but the type is declared without `export`, which breaks downstream type bundling (`vp build` MISSING_EXPORT). core's build adds the missing `export` when copying vite's type defs. - Remove vp build's synthetic cache config (env: [VITE_*], manual input excludes). All-None EnabledCacheConfig keeps caching enabled with auto input/output inference (output restoration); vp dev stays disabled. - Snap tests: vp-build-auto-output-restoration, vp-build-auto-tracked-env. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…nvs) Vite reports its inputs/outputs/envs to the `vp` runner via `@voidzero-dev/vite-task-client`, so `vp build` no longer needs a hand-synthesized cache config. - Bump vite-task git deps to c44d7c33 (runner-aware IPC server/client + embedded napi addon); regenerate run-config.ts for the new task-config types. - Point the vite behind vp build/vp dev to latest vitejs/vite (c13a37b53), which carries the vite-task-client integration. vite lists vite-task-client in devDependencies, so it is bundled into vite's output (and thus into core) the same way as vite's other bundled deps (cac, esbuild, ...) — no extra dependency or build wiring needed. - Work around an upstream vite dts bug (vitejs/vite#21863): `node/index.ts` re-exports `KnownQueryTypeMap` but the type is declared without `export`, which breaks downstream type bundling (`vp build` MISSING_EXPORT). core's build adds the missing `export` when copying vite's type defs. - Remove vp build's synthetic cache config (env: [VITE_*], manual input excludes). All-None EnabledCacheConfig keeps caching enabled with auto input/output inference (output restoration); vp dev stays disabled. - Snap tests: vp-build-auto-output-restoration, vp-build-auto-tracked-env. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…nvs) Vite reports its inputs/outputs/envs to the `vp` runner via `@voidzero-dev/vite-task-client`, so `vp build` no longer needs a hand-synthesized cache config. - Bump vite-task git deps to c44d7c33 (runner-aware IPC server/client + embedded napi addon); regenerate run-config.ts for the new task-config types. - Point the vite behind vp build/vp dev to latest vitejs/vite (c13a37b53), which carries the vite-task-client integration. vite lists vite-task-client in devDependencies, so it is bundled into vite's output (and thus into core) the same way as vite's other bundled deps (cac, esbuild, ...) — no extra dependency or build wiring needed. - Work around an upstream vite dts bug (vitejs/vite#21863): `node/index.ts` re-exports `KnownQueryTypeMap` but the type is declared without `export`, which breaks downstream type bundling (`vp build` MISSING_EXPORT). core's build adds the missing `export` when copying vite's type defs. - Remove vp build's synthetic cache config (env: [VITE_*], manual input excludes). All-None EnabledCacheConfig keeps caching enabled with auto input/output inference (output restoration); vp dev stays disabled. - Snap tests: vp-build-auto-output-restoration, vp-build-auto-tracked-env. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…nvs) Vite reports its inputs/outputs/envs to the `vp` runner via `@voidzero-dev/vite-task-client`, so `vp build` no longer needs a hand-synthesized cache config. - Bump vite-task git deps to c44d7c33 (runner-aware IPC server/client + embedded napi addon); regenerate run-config.ts for the new task-config types. - Point the vite behind vp build/vp dev to latest vitejs/vite (c13a37b53), which carries the vite-task-client integration. vite lists vite-task-client in devDependencies, so it is bundled into vite's output (and thus into core) the same way as vite's other bundled deps (cac, esbuild, ...) — no extra dependency or build wiring needed. - Work around an upstream vite dts bug (vitejs/vite#21863): `node/index.ts` re-exports `KnownQueryTypeMap` but the type is declared without `export`, which breaks downstream type bundling (`vp build` MISSING_EXPORT). core's build adds the missing `export` when copying vite's type defs. - Remove vp build's synthetic cache config (env: [VITE_*], manual input excludes). All-None EnabledCacheConfig keeps caching enabled with auto input/output inference (output restoration); vp dev stays disabled. - Snap tests: vp-build-auto-output-restoration, vp-build-auto-tracked-env. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…nvs) Vite reports its inputs/outputs/envs to the `vp` runner via `@voidzero-dev/vite-task-client`, so `vp build` no longer needs a hand-synthesized cache config. - Bump vite-task git deps to c44d7c33 (runner-aware IPC server/client + embedded napi addon); regenerate run-config.ts for the new task-config types. - Point the vite behind vp build/vp dev to latest vitejs/vite (c13a37b53), which carries the vite-task-client integration. vite lists vite-task-client in devDependencies, so it is bundled into vite's output (and thus into core) the same way as vite's other bundled deps (cac, esbuild, ...) — no extra dependency or build wiring needed. - Work around an upstream vite dts bug (vitejs/vite#21863): `node/index.ts` re-exports `KnownQueryTypeMap` but the type is declared without `export`, which breaks downstream type bundling (`vp build` MISSING_EXPORT). core's build adds the missing `export` when copying vite's type defs. - Remove vp build's synthetic cache config (env: [VITE_*], manual input excludes). All-None EnabledCacheConfig keeps caching enabled with auto input/output inference (output restoration); vp dev stays disabled. - Snap tests: vp-build-auto-output-restoration, vp-build-auto-tracked-env. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…nvs) Vite reports its inputs/outputs/envs to the `vp` runner via `@voidzero-dev/vite-task-client`, so `vp build` no longer needs a hand-synthesized cache config. - Bump vite-task git deps to c44d7c33 (runner-aware IPC server/client + embedded napi addon); regenerate run-config.ts for the new task-config types. - Point the vite behind vp build/vp dev to latest vitejs/vite (c13a37b53), which carries the vite-task-client integration. vite lists vite-task-client in devDependencies, so it is bundled into vite's output (and thus into core) the same way as vite's other bundled deps (cac, esbuild, ...) — no extra dependency or build wiring needed. - Work around an upstream vite dts bug (vitejs/vite#21863): `node/index.ts` re-exports `KnownQueryTypeMap` but the type is declared without `export`, which breaks downstream type bundling (`vp build` MISSING_EXPORT). core's build adds the missing `export` when copying vite's type defs. - Remove vp build's synthetic cache config (env: [VITE_*], manual input excludes). All-None EnabledCacheConfig keeps caching enabled with auto input/output inference (output restoration); vp dev stays disabled. - Snap tests: vp-build-auto-output-restoration, vp-build-auto-tracked-env. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Summary
In Vite 5.1 (released Feb 8, 2024), the
asoption in theimport.meta.globfunction was deprecated. The official recommendation was to switch to thequeryoption, e.g.:const myGlobImports = import.meta.glob("./path/*.csv", { - as: "raw", + query: "?raw", eager: true, import: "default", });Unfortunately, this loses some type information; specifically, TypeScript infers
myGlobImportsasRecord<string, unknown>instead ofRecord<string, string>(or aRecordpointing toPromises returningunknownorstring, respectively, ifeagerisfalse) after making this change. The reason for this is becauseimportGlob.d.tsdoes not have an overload which infers the type of the import fromquerywhen possible; there is only an overload which infers the type fromas.Changes
This PR adds an overload in
importGlob.d.tsthat matches the logic of the existingasoverload but works withquery, allowing users to migrate fromastoquerywhen usingimport.meta.globwithout losing type information (the current workaround is unsafely casting withas unknown as Record<string, string>).Tests?
I've applied this patch to an internal project and it seems to be working; I've tested with
eagerbothtrueandfalseand swapping betweenasandquery(the new overload needs to go above the previous overload because it is more specific and TypeScript applies overloads top-to-bottom).I didn't see a way to test these types other than running
pnpm build(which runspnpm build-typesinternally) — for what it's worth, the local build did complete without errors. Let me know if there is anything else I can do to test.