英文:
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'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 }) => {
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>
</>
);
});
**Deb dependencies using regarding 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",
[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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论