英文:
ESLint complains that SvelteKit's App namespace is not defined
问题
在我的 `+error.svelte` 页面中,我想导入一个组件,然后传入错误对象。
```svelte
<script lang="ts">
  import { page } from "$app/stores";
  const error = $page.error;
</script>
<RenderError {error} />
在我的组件中,我有一个简单的变量,触发 eslint 中的错误:
<script lang="ts">
  export let error: App.Error;
</script>
错误:'App' 未定义。eslint(no-undef)
但是 App 命名空间是全局的,对吗?我该如何消除这个错误?
我的 app.d.ts 文件:
declare global {
  namespace App {
    interface Error {
      errorId?: string;
    }
    // interface Locals {}
    // interface PageData {}
    // interface Platform {}
  }
}
 
export {};
英文:
In my +error.svelte page I want to import a component, and then pass in the error object.
<script lang="ts">
  import { page } from "$app/stores";
  const error = $page.error;
</script>
<RenderError {error} />
In my component, I have this simple variable which triggers an error in eslint:
<script lang="ts">
  export let error: App.Error;
</script>
Error: 'App' is not defined. eslint(no-undef)
But the App namespace is global, right? How do I get rid of this error?
My app.d.ts file:
declare global {
  namespace App {
    interface Error {
      errorId?: string;
    }
    // interface Locals {}
    // interface PageData {}
    // interface Platform {}
  }
}
 
export {};
答案1
得分: 1
这可以通过将 App 命名空间作为 eslint 的全局变量来进行临时修复。
.eslintrc
{
  //...
  "root": true,
  "globals": {
    "App": "writable"
  }
}
英文:
This can be fixed temporally by adding the App namespace as an eslint global.
.eslintrc
{
  //...
  "root": true,
  "globals": {
    "App": "writable"
  }
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论