小编Pau*_*l A的帖子

无法将 typescript 类型应用于派生的 svelte 存储

我有一个工作派生商店,名为selectedDocument in svelte。当我尝试向其中添加正确的类型时,出现以下 TS linting 错误。(并且智能感知不起作用)

TS Linting 错误

关于selectedDocument存储的定义

Expected 2 type arguments, but got 1.ts(2558)
Run Code Online (Sandbox Code Playgroud)

上 ([$selectedDocId, $userDocuments])

Type '{ view_id: never; user_id: never; doc_id: never; user_name: never; user_avatar: never; cardMap: never; cards: never; }' must have a '[Symbol.iterator]()' method that returns an iterator.ts(2488)
Run Code Online (Sandbox Code Playgroud)

代码

商店可以工作,类型可以与其他类似数据一起工作

接口

export interface MainView {
  view_id: string;
  user_id: string;
  doc_id: string;
  user_name: string;
  user_avatar: string;
  cardMap: CardMap;
  cards: {
    [key: string]: Card;
  };
}
export interface Document {
    doc_id: string; …
Run Code Online (Sandbox Code Playgroud)

typescript svelte svelte-store

2
推荐指数
1
解决办法
2482
查看次数

jsconfig 路径别名不起作用 Sveltekit

我正在使用 svelte 套件(带有打字稿),并且创建了一些短链接,但无法使新链接“$base”正常工作。我在这里添加了短链接

./jsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    "baseUrl": ".",
    "paths": {
      "$lib":   ["src/lib"],
      "$lib/*": ["src/lib/*"],
      "$base":  ["src/baseApp"],
      "$base/*":["src/baseApp/*"]
    }
  },
  "include": ["src/**/*.d.ts", "src/**/*.js", "src/**/*.svelte"]
}
Run Code Online (Sandbox Code Playgroud)

也没有智能感知 在此输入图像描述

有关 jsconfig.json 的更多详细信息请参见此处

我还在这里发现了与 NEXT 类似的问题

我尝试了这个但没有成功

除了 jsconfig.json 之外,我还尝试将路径添加到 tsconfig.json 文件中

{
    "extends": "./.svelte-kit/tsconfig.json",
    "compilerOptions": {
        "allowJs": true,
        "checkJs": true,
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,
        "resolveJsonModule": true,
        "skipLibCheck": true,
        "sourceMap": true,
        "strict": true
    },
    "paths": {
        "$lib":   ["src/lib"],
        "$lib/*": ["src/lib/*"],
        "Base":  ["src/baseApp"],
        "Base/*":["src/baseApp/*"]
      }
}

Run Code Online (Sandbox Code Playgroud)

javascript typescript visual-studio-code sveltekit

1
推荐指数
1
解决办法
4263
查看次数