我正在使用 Vite 创建一个新的 React + TypeScript 项目。
创建项目后,根文件夹中有两个 TypeScript 配置文件:tsconfig.json和tsconfig.node.json. 以下是每一篇的内容:
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": false,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
Run Code Online (Sandbox Code Playgroud)
{
"compilerOptions": {
"composite": true,
"module": "esnext",
"moduleResolution": "node"
},
"include": ["vite.config.ts"]
}
Run Code Online (Sandbox Code Playgroud)
为什么我们需要两个?
第二个是做什么的?
我可以删除第二个吗?
在命令行上,我可以打开一个目录,如:
code .
Run Code Online (Sandbox Code Playgroud)
现在,我希望在另一个窗口中打开并显示两个相同的指令.
(它没有拆分编辑器)
然后,我又试了一次.
code .
Run Code Online (Sandbox Code Playgroud)
没啥事儿.
还有一个目录已打开.
如何实现这样的任务?
我已经四处寻找解决这个问题的方法了.所有这些都建议添加"jsx": "react"到您的tsconfig.json文件.我做了什么.另外一个是补充"include: []",我也做了.但是,当我尝试编辑.tsx文件时,我仍然收到错误.下面是我的tsconfig文件.
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"allowJs": true,
"checkJs": false,
"jsx": "react",
"outDir": "./build",
"rootDir": "./lib",
"removeComments": true,
"noEmit": true,
"pretty": true,
"skipLibCheck": true,
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true
},
"include": [
"./lib/**/*"
],
"exclude": [
"node_modules"
]
}
Run Code Online (Sandbox Code Playgroud)
任何的意见都将会有帮助.我正在使用babel 7来编译env,react和typescript预设的所有代码.如果你们需要更多文件来帮助调试这个,请告诉我.
我们在当前项目中使用 React 和 TypeScript,我遇到了以下行为。
import React, { Component } from 'react';
Run Code Online (Sandbox Code Playgroud)
我用下面的一行替换上面的行,因为它似乎Component只使用导入。
import { Component } from 'react';
Run Code Online (Sandbox Code Playgroud)
我被抛出以下错误
错误:“React”指的是 UMD 全局,但当前文件是一个模块。考虑改为添加导入。
我尝试在 Stack 和 GitHub 上查找,发现很少有文章和讨论,但仍不清楚为什么会发生这种情况。
会更感兴趣是 React 还是 Typescript 抛出它以及为什么?不是修复它的方法。
还有一些关于 UMD 的光线,为什么在这里使用它?
我在.tsx文件中添加View组件时遇到此错误.
我想使用带有打字稿的 jest 酶测试 react 应用程序中的一个组件,我按照jest 中的说明进行操作, 但由于某种原因我得到: SyntaxError: Unexpected token <
我可以测试测试一些功能没有问题,但是当我使用组件时出现错误,
这是开玩笑的配置 package.json
"jest": {
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testMatch": ["**/__tests__/*.(ts|tsx)"],
"snapshotSerializers": ["enzyme-to-json/serializer"],
"setupFilesAfterEnv": ["<rootDir>/src/setupEnzyme.ts"],
"unmockedModulePathPatterns": ["node_modules/react/", "node_modules/enzyme/"]
}
Run Code Online (Sandbox Code Playgroud)
酶配置
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
configure({ adapter: new Adapter() });
Run Code Online (Sandbox Code Playgroud)
export default class TesComponent extends Component {
render(){
return (
<div>test</div>
)
}
}
Run Code Online (Sandbox Code Playgroud)
import { shallow } from 'enzyme'
import TestCompoenent from '../TestComponent'
test('component testing', () => {
const component …Run Code Online (Sandbox Code Playgroud) typescript ×4
reactjs ×3
javascript ×2
enzyme ×1
jestjs ×1
jsx ×1
react-native ×1
tsconfig ×1
tsx ×1
vite ×1