Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vite can't resolve import .d.ts file

I want to import type from type.d.ts file

import type { StateDefinition } from '../type'

vite cannot find file and throw error enter image description here

So I should add extention .d.ts

import type { StateDefinition } from '../type.d.ts'

but I will get ts error in vscode enter image description here

anyone can tell me how to fix it?

like image 410
shuaige Avatar asked Oct 21 '25 04:10

shuaige


1 Answers

I had this exact same issue and figured out the following cause: if you're importing both interfaces and enums in the same statement like:

import { SomeType, AnEnum } from '@/types/general'

The import will be causing the error above. However, if you replace it to:

import type { SomeType } from '@/types/general.d.ts'`

Then it will work. Just put any enums you might have somewhere else.

like image 200
t56k Avatar answered Oct 23 '25 20:10

t56k



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!