ESLint抱怨SvelteKit的App命名空间未定义。

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

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.

&lt;script lang=&quot;ts&quot;&gt;
  import { page } from &quot;$app/stores&quot;;
  const error = $page.error;
&lt;/script&gt;

&lt;RenderError {error} /&gt;

In my component, I have this simple variable which triggers an error in eslint:

&lt;script lang=&quot;ts&quot;&gt;
  export let error: App.Error;
&lt;/script&gt;

Error: &#39;App&#39; 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

{
  //...
  &quot;root&quot;: true,
  &quot;globals&quot;: {
    &quot;App&quot;: &quot;writable&quot;
  }
}

huangapple
  • 本文由 发表于 2023年2月27日 17:43:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75578842.html
匿名

发表评论

匿名网友

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

确定