ESLint 提示出错 – 在 Qwik 中出现解析错误:需要标识符。

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

ESLint is giving warning - Parsing error: Identifier expected in Qwik

问题

I see you want a translation of the code portion. Here it is:

在我的VSCode编辑器中,我收到了以下来自eslint的警告:

Parsing error: Identifier expected.eslint
(property) bind: value: Signal


我可以理解TypeScript在警告我由于某些类型不匹配而引发了错误,但我无法弄清楚如何修复它。

以下是我代码的简化版本 -

```typescript
export default component$(() => {
    const action = useCreateUserAccount();
    const nameSig = useSignal(defaultValues.name);
    const emailSig = useSignal(defaultValues.email);
    const passwordSig = useSignal(defaultValues.password);

    useTask$(({ track }) => {
        const status = track(() => action.value?.status);
        if (status) {
            nameSig.value = defaultValues.name;
            emailSig.value = defaultValues.email;
            passwordSig.value = defaultValues.password;
        }
    });

    return (
        <>
            <Form class="space-y-4 md:space-y-6" action={action}>
                <div>
                    <label for="email" class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Name</label>
                    <input type="text" name="name" id="name" bind:value={nameSig} placeholder="Write your name" />
                </div>
            </Form>
        </>
    );
});

有关TypeScript和ESLint的依赖关系:

  • "@types/eslint": "8.37.0",
  • "@types/node": "^20.1.4",
  • "@typescript-eslint/eslint-plugin": "5.59.5",
  • "@typescript-eslint/parser": "5.59.5",
  • "eslint": "8.40.0",
  • "eslint-plugin-qwik": "~1.2.0",

请注意,这是您代码的翻译部分。

<details>
<summary>英文:</summary>

Getting the following warning in my vscode editor from eslint

Parsing error: Identifier expected.eslint
(property) bind: value: Signal<string>


[![enter image description here][1]][1]

I can understand the typescript yelling at me due to some type mismatch, but I can&#39;t figure out how to fix this.

Here is a trim down version of my code -

export default component$(() => {
const action = useCreateUserAccount();
const nameSig = useSignal(defaultValues.name);
const emailSig = useSignal(defaultValues.email);
const passwordSig = useSignal(defaultValues.password);

useTask$(({ track }) =&gt; {
    const status = track(() =&gt; action.value?.status);
    if (status) {
        nameSig.value = defaultValues.name;
        emailSig.value = defaultValues.email;
        passwordSig.value = defaultValues.password;
    }
});


return (
    &lt;&gt;            
        &lt;Form class=&quot;space-y-4 md:space-y-6&quot; action={action} &gt;
            &lt;div&gt;
                &lt;label for=&quot;email&quot; class=&quot;block mb-2 text-sm font-medium text-gray-900 dark:text-white&quot;&gt;Name&lt;/label&gt;
                &lt;input type=&quot;text&quot; name=&quot;name&quot; id=&quot;name&quot; bind: value={nameSig} placeholder=&quot;Write your name&quot; /&gt;
            &lt;/div&gt;
        &lt;/Form&gt;
    &lt;/&gt;
);

});



**Deb dependencies using regarding Typescript &amp; ESLint.**

- &quot;@types/eslint&quot;: &quot;8.37.0&quot;,

- &quot;@types/node&quot;: &quot;^20.1.4&quot;,

- &quot;@typescript-eslint/eslint-plugin&quot;: &quot;5.59.5&quot;,

- &quot;@typescript-eslint/parser&quot;: &quot;5.59.5&quot;,

- &quot;eslint&quot;: &quot;8.40.0&quot;,

- &quot;eslint-plugin-qwik&quot;: &quot;~1.2.0&quot;,



  [1]: https://i.stack.imgur.com/ojvDq.png

</details>


# 答案1
**得分**: 2

API是`bind:value`(无空格),这里是[文档](https://qwik.builder.io/docs/components/rendering/#bind-attribute)

在VSCode中,`Typescript和Javascript语言特性`的代码检查工具会因为添加空格而混淆`bind:value`和许多其他属性。请使用[Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)来检查你的代码,因为它工作得更好。

<details>
<summary>英文:</summary>

the API is `bind:value` (without space) here is the 
(https://qwik.builder.io/docs/components/rendering/#bind-attribute) In VSCode, `Typescript and Javascript Language Features` linter mess up `bind:value` and many other attributes because it adds spaces. Please use [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) to lint your code because it works better. </details>

huangapple
  • 本文由 发表于 2023年7月3日 03:29:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76600483.html
匿名

发表评论

匿名网友

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

确定