Tìm kiếm trang web

reactjs - Không tìm thấy tệp. Typescript react


Tôi mới bắt đầu triển khai Typescript trong các dự án React mới.

Tôi đã chạy yarn create react-app my-app --template typescript, và tôi muốn biết tất cả các tệp nào không hữu ích cho tôi và tôi có thể xóa. Giống như với js, tôi xóa mọi thứ và chỉ giữ lại app.js, app.css và index.

Tuy nhiên khi tôi làm điều đó ở đây, tôi nhận được một lỗi.

Lỗi báo cho tôi:

undefined TypeScript error in undefined(undefined,undefined): File '/mnt/d/NodeJs/my-todo-list/src/App.test.tsx' not found.   The file is in the program because:
    Matched by include pattern 'src' in '/mnt/d/NodeJs/my-todo-list/tsconfig.json'  TS6053

Tệp tsconfig.json của tôi:

{
    "name": "my-todo-list",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
        "@testing-library/jest-dom": "^5.11.4",
        "@testing-library/react": "^11.1.0",
        "@testing-library/user-event": "^12.1.10",
        "@types/jest": "^26.0.15",
        "@types/node": "^12.0.0",
        "@types/react": "^17.0.0",
        "@types/react-dom": "^17.0.0",
        "react": "^17.0.2",
        "react-dom": "^17.0.2",
        "react-scripts": "4.0.3",
        "typescript": "^4.1.2",
        "web-vitals": "^1.0.1"
    },
    "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject"
    },
    "eslintConfig": {
        "extends": [
          "react-app",
          "react-app/jest"
        ]
    },
    "browserslist": {
        "production": [
            ">0.2%",
            "not dead",
            "not op_mini all"
        ],
        "development": [
            "last 1 chrome version",
            "last 1 firefox version",
            "last 1 safari version"
        ]
    }
}

Tôi muốn biết tất cả những gì tôi có thể xóa để bắt đầu một dự án mới trong React với TypeScript, bao gồm cả việc tôi có thể xóa các tệp react-app-env.d.ts và reportWebVitals.ts không

Cây nguồn:

Câu trả lời #1

vào tệp settings.json của trình soạn thảo của bạn (ctrl+shift + p trong vscode cho win), sau đó thêm và lưu

"typescript.validate.enable":true,