obsidian 插件开发请教

有没有开发 obsidian 插件的佬友?我想使用 “obsidian-typings” 来补充官方未提供的类型和接口。我按照 Getting Started | Obsidian Typings 配置的 tsconfig.json 内容如下:

{
  "compilerOptions": {
    "lib": ["DOM", "ES2021"],
    "jsx": "preserve",
    "target": "ES2021",
    "noEmit": true,
    "skipLibCheck": true,
    "jsxImportSource": "vue",
    "useDefineForClassFields": true,

    /* modules */
    "module": "ESNext",
    "moduleDetection": "force",
    "moduleResolution": "node",
    "verbatimModuleSyntax": true,
    "resolveJsonModule": true,
    "allowImportingTsExtensions": true,
    "noUncheckedSideEffectImports": true,

    /* type checking */
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "baseUrl": ".",
    "paths": {
      "@*": ["src/*"]
    },
    "types": ["obsidian-typings"]
  },
  "include": ["src"]
}

但是对于 app.workspace.getActiveFileView,vsc 仍然提示:属性“getActiveFileView”在类型“Workspace”上不存在。折腾了好久也没折腾明白该如何实现 obsidian-typings 对 obsidian 的类型扩充。佬友们,求助啊啊啊啊 :tieba_087: :tieba_087: :tieba_087:

都有Workspace了,类型应该没问题。 有没有可能是因为app.workspace.getActiveFileView() 是方法而不是属性

  1. 确认obsidian-types升级到了最新版
  2. ctrl+左键点击到workspace里面看看有没有这个方法

我查看过 obsidian-typings 的包,里面是有对 Workspace.getActiveFileView() 的补充定义。

所以你打括号了吗

obsidian-typings 是最新版。官方的 Workspace 没有这个方法,obsidian-typings 的有。不想弄个 .d.ts 文件手动补充类型提示,不然以后用到官方没给的就要手动弄一个太麻烦了 :tieba_087:

image

:tieba_087:难顶

moduleResolution换成其他bundler或者nodenext的试试

还是不行,难不成是 vsc 的问题?

好吧,并不是 vsc 的问题,webstorm 一样提示。那就是 obsidian-typings 没用对或者 obsidian-typings 有问题。不应该呀,我也没看到 github issue 上有人提出类似的问题。

难顶 :tieba_087:

为啥要用这个包,刚刚试了一下tm拉一大坨没用的包 :sweat_smile:

网上好像就这个包有对官方接口进行补充。不想定义那么多 d.ts 文件把 src 搞乱。现在看来我也只能搞 d.ts 了

试试这个 ./node_modules/obsidian-typings/dist/cjs/types.d.cts

搞定了,官方给定 types 配置没用…,最后换成 include 才搞定…

image

谢了佬友,大大滴肯定:tieba_013:

哈哈哈,是我想太简单了