为什么我收到此 TypeScript 错误消息以及如何修复它?
找不到模块“@env”或其相应的类型声明
当我使用这个时会发生这种情况:
import { FB_ID } from '@env';
Run Code Online (Sandbox Code Playgroud)
Tt 不应命名为 @env,它应命名为“react-native-dotenv”,但在我的配置中我将其命名为 @env,以便我可以使用它,并且可以检索 FB_ID 值。它有效,但我收到 TypeScript 错误。
这是我设置 moduleName 的地方:
import { FB_ID } from '@env';
Run Code Online (Sandbox Code Playgroud)
那么我该如何解决它呢?
ts配置:
['module:react-native-dotenv', {
"envName": "APP_ENV",
"moduleName": "@env",
"path": ".env",
"blocklist": null,
"allowlist": null,
"safe": false,
"allowUndefined": true,
"verbose": false
}]
Run Code Online (Sandbox Code Playgroud) 我已将我的 Angular 应用程序从 13 更新到 14。更新后,在 vs code 中打开组件类后出现以下错误。
类正在使用 Angular 功能,但未进行修饰。请添加显式的 Angular 装饰器
我已经检查过这个问题
但我没有在应用程序中使用任何继承性。
但应用程序运行完美。如何消除该错误?
ts.confing
/* 要了解有关此文件的更多信息,请参阅: https: //angular.io/config/tsconfig。*/
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": false,
"strict": false,
"allowSyntheticDefaultImports":true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": true,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2022",
"module": "es2022",
"lib": [
"es2022",
"dom"
],
"paths": {
"stream": [ "./node_modules/stream-browserify" ]
},
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": …
Run Code Online (Sandbox Code Playgroud) 我看到了一些关于这个问题的问题,但没有一个不起作用我有一个nodejs项目和Typescript。我不喜欢使用相对路径。当我在 tsconfig 中设置路径时,出现以下错误:
找不到模块“@app/controllers/main”
// main.ts
export const fullName = "xxxx";
...
// app.ts
import { fullName } from '@app/controllers/main'
...
Run Code Online (Sandbox Code Playgroud)
这是我的项目的结构:
-node_modules
-src
----controllers
---------------main.ts
----app.ts
-package.json
-tsconfig.json
Run Code Online (Sandbox Code Playgroud)
ts配置:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"strict": true,
"baseUrl": ".",
"paths": {
"@app/*": ["src/*"]
},
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题出在哪里?
提前致谢。
我正在用 TypeScript 编写 React 组件的前端测试。由于代码来自更有经验的程序员,因此某些数据类型对我来说似乎有点新。现在我有了一个使用“Dispatch<SetStateAction>”作为数据类型定义的道具。我注意到使用 useState-Hook 的 set-property 是有效的,但我不太确定这是否是应该使用 prop 的方式。供参考:该道具称为“onFullScreenClick”。我将非常感谢您对最有可能放入的内容进行解释和示例
我的问题很简单。鉴于此代码:
const array = [1, 2, 3, 4, 5];
const map01 = array.map((v) => v % 2 ? "" : "");
// ^? string[]
const map02 = array.map((v) => v % 2 ? "odd" : "even");
// ^? ("odd" | "even")[]
const map03 = array.map((v) => v % 2 ? "!" : "");
// ^? ("" | "!")[]
Run Code Online (Sandbox Code Playgroud)
为什么 TypeScript 会做出如此奇怪的推论?不应该map01
被推断为""[]
?
我有一个测试:
import { convertHeicToPng } from './heicUtils';
class Worker {
url: string;
onmessage: (m?: any) => void;
constructor(stringUrl: string) {
this.url = stringUrl;
this.onmessage = () => {};
}
postMessage(msg: any) {
this.onmessage(msg);
}
}
(window.Worker as any) = Worker;
describe('test heicUtils', () => {
test('should convert HEIC to PNG', async () => {
const file = new File([''], 'test.heic', { type: 'image/heic' });
const base64 = await convertHeicToPng(file);
expect(base64).toContain('data:image/png;base64');
});
});
Run Code Online (Sandbox Code Playgroud)
在 中heicUtils
,我使用的是heic2any,它使用 WebWorkers。我如何才能正确地模拟 Worker …
我正在尝试安装@chakra-ui
它并将其与 Next 一起使用,但它根本不起作用。我卸载并重新安装了它,但它不起作用。
我使用的npm i @chakra-ui/react @emotion/react@^11 @emotion/styled@^11 framer-motion@^6
安装时没有显示任何错误,但是当我去使用import {} from '@chakra-ui/react'
它时它不起作用,它说:
找不到模块“@chakra-ui/react”或其相应的类型声明。
在浏览器中,通常有在历史记录中前进和后退的箭头按钮:
这些按钮可以通过剧作家点击吗?
他们没有任何元素,所以我想知道这是否可能......
await navigationObject(page).backButton.click();
Run Code Online (Sandbox Code Playgroud) tsconfig.json
{
"compilerOptions": {
"sourceMap": true,
"outDir": "dist",
"target": "es5",
"lib": ["es6", "dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
Run Code Online (Sandbox Code Playgroud)
我在 tsconfig.json 中遇到此错误,因此由于此错误,当我构建 nextjs 项目时,我无法运行“npm run build”此命令。有人知道如何修复此问题吗?
type A = [{a: 1}, {a: 'x'}]
type TupleToUnion<T, K> = ...
TupleToUnion<A, 'a'> // expected to be `1 | 'x'`
Run Code Online (Sandbox Code Playgroud)
我该如何定义TupleToUnion
?
typescript ×10
javascript ×2
next.js ×2
reactjs ×2
angular ×1
chakra-ui ×1
jestjs ×1
node.js ×1
playwright ×1
react-hooks ×1
react-native ×1
tsconfig ×1
web-worker ×1
yup ×1