英文:
Failure to import a typescript interface from a sibling folder in my src directory using svelte and vite
问题
I am trying to import an interface, the first one, into my svelte project.
In src/interface/EnabledSignUpArgs.interface.ts
there is this code
export interface EnabledSignupArgs {
email: string
username: string
password: string
confirmedPassword: string
agreedToTOS: boolean
agreedToPrivacyPolicy: boolean
}
// I also tried adding this
export default EnabledSignupArgs
In 2 files I am trying to
import { EnabledSignupArgs } from "../../interface/EnabledSignUpArgs.interface"
and
import { EnabledSignupArgs } from "../interface/EnabledSignUpArgs.interface"
According to my IDE, this is fine but the HTML the server spits out includes
The requested module
/src/interface/EnabledSignUpArgs.interface.ts
does not provide an export namedEnabledSignupArgs
I have tried: (1) restarting my dev server (2) moving the file to a different directory (3) making it a default export, but I am out of ideas!
Here is my tsconfig.json
:
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"moduleResolution": "node",
"module": "es2020",
"lib": ["es2020", "DOM"],
"target": "es2020",
"importsNotUsedAsValues": "preserve",
"isolatedModules": false,
"resolveJsonModule": true,
"sourceMap": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"allowJs": true,
"checkJs": true,
"paths": {
"$components/*": ["src/lib/components/*"],
"$styles/*": ["src/lib/styles/*"],
"$utils/*": ["src/lib/utils/*"],
"$src/*": ["src/*"],
"$lib": ["src/lib"],
"$lib/*": ["src/lib/*"]
},
"types": ["jest"]
},
"include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.ts", "src/**/*.svelte"]
}
英文:
I am trying to import an interface, the first one, into my svelte project.
In src/interface/EnabledSignUpArgs.interface.ts
there is this code
export interface EnabledSignupArgs {
email: string
username: string
password: string
confirmedPassword: string
agreedToTOS: boolean
agreedToPrivacyPolicy: boolean
}
// i also tried adding this
export default EnabledSignupArgs
In 2 files I am trying to
import { EnabledSignupArgs } from "../../interface/EnabledSignUpArgs.interface"
and
import { EnabledSignupArgs } from "../interface/EnabledSignUpArgs.interface"
according to my IDE, this is fine but the html the server spits out includes
> The requested module '/src/interface/EnabledSignUpArgs.interface.ts'
does not provide an export named EnabledSignupArgs
I have tried: (1) restarting my dev server (2) moving the file to a different directory (3) making it a default export, but I am out of ideas!
Here is my tsconfig.json
:
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"moduleResolution": "node",
"module": "es2020",
"lib": ["es2020", "DOM"],
"target": "es2020",
"importsNotUsedAsValues": "preserve",
"isolatedModules": false,
"resolveJsonModule": true,
"sourceMap": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"allowJs": true,
"checkJs": true,
"paths": {
"$components/*": ["src/lib/components/*"],
"$styles/*": ["src/lib/styles/*"],
"$utils/*": ["src/lib/utils/*"],
"$src/*": ["src/*"],
"$lib": ["src/lib"],
"$lib/*": ["src/lib/*"]
},
"types": ["jest"]
},
"include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.ts", "src/**/*.svelte"]
}
答案1
得分: 2
询问起到了作用。解决方案:
import type { interfaceName } from "../path/to/interface"
英文:
Asking did the trick. Solution:
import type { interfaceName } from "../path/to/interface"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论