TS2322 Type Element is not assignable to type ReactNode-出现在preact

出现TS2322 Type Element is not assignable to type ReactNode

  • 大部分都是ts的问题,没有识别到,目前在preact出现过这种

解决

  • tsconfig.json添加下面内容
json 复制代码
    "paths": {
      "react": ["./node_modules/preact/compat"],
      "react-dom": ["./node_modules/preact/compat"]
    }
  • tsconfig.json完整内容
java 复制代码
{
  "compilerOptions": {
    "target": "ESNext",
    "useDefineForClassFields": true,
    "lib": ["DOM", "DOM.Iterable", "ESNext"],
    "allowJs": false,
    "skipLibCheck": true,
    "esModuleInterop": false,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "ESNext",
    "moduleResolution": "Node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "jsxImportSource": "preact",
    "paths": {
      "react": ["./node_modules/preact/compat"],
      "react-dom": ["./node_modules/preact/compat"]
    }
  },
  "include": ["src"],
  "references": [
    {
      "path": "./tsconfig.node.json"
    }
  ]
}
相关推荐
有一个好名字13 小时前
claude code安装
linux·运维·前端
BIBABULALA13 小时前
Mini Virtual Machine — 可视化虚拟机模拟器(91行)
前端·css·css3
筱璦13 小时前
期货软件开发「启动加载页 / 初始化窗口」
前端·c#·策略模式·期货
只与明月听13 小时前
RAG深入学习之Emabedding
前端·python·面试
We་ct13 小时前
React Scheduler & Lane 详解
前端·react.js·前端框架·reactjs·个人开发·任务调度·优先
kgduu13 小时前
js之json处理
前端·javascript·json
@木尘14 小时前
前端面试【 八股文篇】
前端·面试·职场和发展
吴佳浩14 小时前
OpenClaw、Claude Code 等 Agent 为什么都选择 Node.js?
前端·人工智能·langchain
小小小小宇14 小时前
React 19 useActionState 深度解析 & Vue 2.7 移植实战
前端
远山枫谷14 小时前
Vue2 vs Vue3 全面对比(含代码示例+迁移指南)
前端·vue.js