在其他线程中,我读到当 eslint 和 tsconfig.json 不在同一工作文件夹中时可能会出现问题,但我在项目的根文件夹中拥有所有文件。不知何故,初始化项目后,抛出的错误似乎尝试在项目的父文件夹中(因此,在项目外部)查找 tsconfig.json:
假设项目位于:'\parentFolder\ProjectRoot' tsconfig 位于路线中:'\parentFolder\ProjectRoot\tsconfig.json
我得到的 eslint 错误(位于 index.ts 的顶部)如下:
解析错误:无法读取文件“ parentFolder \tsconfig.json”
\parentFolder\ProjectRoot 的内容是:
达到这一点的步骤是:
.eslintrc:
{
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking"
],
"plugins": ["@typescript-eslint"],
"env": {
"browser": true,
"es6": true
},
"rules": {
"@typescript-eslint/semi": ["error"],
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/no-unused-vars": [
"error", { "argsIgnorePattern": …Run Code Online (Sandbox Code Playgroud) 我有以下端点设置来在测试运行后重置数据库:
import { getConnection } from 'typeorm';
import express from 'express';
const router = express.Router();
const resetDatabase = async (): Promise<void> => {
const connection = getConnection();
await connection.dropDatabase();
await connection.synchronize();
};
// typescript-eslint throws an error in the following route:
router.post('/reset', async (_request, response) => {
await resetTestDatabase();
response.status(204).end();
});
export default router;
Run Code Online (Sandbox Code Playgroud)
此后的整个路线都async带有下划线,并带有 typescript-eslint 错误Promise returned in function argument where a void return was expected.
该应用程序工作完美,但我不确定我是否应该执行更安全的实现,或者只是忽略/禁用此应用程序的 Eslint。知道该代码有什么问题吗?
我正在尝试在 TypeScript 项目中创建以下形状的自定义 Apollo Client 突变挂钩:
const customApolloMutation = () => {
const [
mutationFunction,
{ data, loading, error, ...result } // or just {...result}
] = useMutation(GRAPHQL_QUERY)
return [mutationFunction,
{ data, loading, error, ...result } // or just {...result}
]
}
export default customApolloMutation ;
Run Code Online (Sandbox Code Playgroud)
一切看起来都很好,但是当我在不同的文件中导入自定义挂钩时,如下所示:
const [mutationFunction, {data, loading, error}] = customApolloMutation();
Run Code Online (Sandbox Code Playgroud)
...所有解构的 props 都会给出 TypeScript 错误,例如Property 'loading' does not exist on type '((options?: MutationFunctionOptions<any, OperationVariables> | undefined) => Promise<FetchResult<any, Record<string, any>, Record<string, any>>>) | { ...; …
hook typescript apollo-client react-hooks react-apollo-hooks
如何template string css在 VS Code 中启用情感语法突出显示?我找到的所有插件都是用于片段的。
它可以工作,css({ camelCaseCssProps:...})但我试图css variables在没有导入的情况下使用主题,我想一般来说我宁愿kebab-case在我的全局样式文件中保留常规的 css 语法:
// index.js
render(
<Global
styles={css`
html {
// css variables (and/or camel-case props)
--color-base: white;
--color-text: #434449;
}
`}
/>
)
Run Code Online (Sandbox Code Playgroud) css syntax-highlighting emotion visual-studio-code styled-components
typescript ×3
eslint ×2
node.js ×2
css ×1
cypress ×1
emotion ×1
express ×1
hook ×1
html ×1
react-hooks ×1
testing ×1
typeorm ×1
validation ×1