-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
Description
Describe the bug
I've created an astro project with basic vite configuration:
/// <reference types="vitest" />
import { getViteConfig } from 'astro/config';
import tsconfigPaths from 'vite-tsconfig-paths';
export default getViteConfig({
plugins: [tsconfigPaths()],
// @ts-expect-error - Vitest config is merged
test: {
include: ['tests/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
typecheck: {
enabled: true,
checker: 'tsc',
include: ['tests/**/*.{test,spec}-d.{ts,mts,cts}'],
},
},
});I've created a polymorphic component and testing for the tests:
import type { ComponentProps, HTMLTag } from 'astro/types';
import { expectTypeOf, test } from 'vitest';
import type Polymorphic from '@/components/html/_polymorphic.astro';
test('Polymorphic types', () => {
type PolymorphicProps<Tag extends HTMLTag> = ComponentProps<
typeof Polymorphic<Tag>
>;
type ButtonProps = PolymorphicProps<'button'>;
expectTypeOf<ButtonProps['as']>().toEqualTypeOf<'button' | undefined>();
// Check specific attributes
type AnchorProps = PolymorphicProps<'a'>;
expectTypeOf<AnchorProps['as']>().toEqualTypeOf<'a' | undefined>();
// href should exist on anchor
expectTypeOf<AnchorProps['href']>().not.toBeNever();
// Test invalid usage
// @ts-expect-error - 'href' is not valid on button (if strict)
const _: ButtonProps = { as: 'button', href: 'bad' };
});I'm receiving:
❯ TS tests/html/_polymorphic.test-d.ts (1 test | 1 failed)
× Polymorphic types
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
FAIL tests/html/_polymorphic.test-d.ts > Polymorphic types
TypeCheckError: Cannot find module '@/components/html/_polymorphic.astro' or its corresponding type declarations.
❯ tests/html/_polymorphic.test-d.ts:3:30
1| import type { ComponentProps, HTMLTag } from 'astro/types';
2| import { expectTypeOf, test } from 'vitest';
3| import type Polymorphic from '@/components/html/_polymorphic.astro';
| ^
4|
5| test('Polymorphic types', () => {
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯
Reproduction
Generally doesn't matter any import of an astro component inside vite causes this. Whilst astro check with the plugin works. Maybe astro needs a plugin but the issue is the difference that was being created.
System Info
System:
OS: Linux 6.18 Arch Linux
CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700H
Memory: 53.10 GB / 62.50 GB
Container: Yes
Shell: 5.9 - /usr/bin/zsh
Binaries:
Node: 24.11.0 - /home/sagi/.local/share/mise/installs/node/24.11.0/bin/node
Yarn: 1.22.22 - /usr/bin/yarn
npm: 11.6.1 - /home/sagi/.local/share/mise/installs/node/24.11.0/bin/npm
pnpm: 10.27.0 - /home/sagi/.local/share/pnpm/pnpm
bun: 1.3.1 - /home/sagi/.local/share/mise/installs/bun/1.3.1/bin/bun
Browsers:
Chromium: 143.0.7499.109
Firefox: 146.0.1
Firefox Developer Edition: 146.0.1
npmPackages:
vitest: ^4.0.16 => 4.0.16Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable