无法从我的src目录中的兄弟文件夹中使用Svelte和Vite导入TypeScript接口。

huangapple go评论59阅读模式
英文:

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 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"]
}
英文:

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"

huangapple
  • 本文由 发表于 2023年2月18日 08:26:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75490366.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定