美文网首页
TypeScript compilerOptions:jsx

TypeScript compilerOptions:jsx

作者: antlove | 来源:发表于2021-04-08 11:13 被阅读0次

    package.json

    {
      "name": "tsc-tsx",
      "version": "1.0.0",
      "main": "index.js",
      "license": "MIT",
      "dependencies": {
        "@types/react": "^17.0.3",
        "typescript": "3.9.9"
      }
    }
    

    tsconfig.json

    {
      "compilerOptions": {
        "jsx": "react",
        "target": "es6",                          
        "module": "commonjs",                     
        "strict": true,                           
      }
    }
    

    index.tsx

    function INode()  {
        return <div>xxx</div>;
    }
    

    "jsx": "react",

    yarn tsc
    生成 index.js

    "use strict";
    function INode() {
        return React.createElement("div", null, "xxx");
    }
    

    "jsx": "react-native",

    yarn tsc
    生成index.js

    "use strict";
    function INode() {
        return <div>xxx</div>;
    }
    

    "jsx": "preserve",

    yarn tsc
    生成 index.jsx

    "use strict";
    function INode() {
        return <div>xxx</div>;
    }
    

    相关文章

      网友评论

          本文标题:TypeScript compilerOptions:jsx

          本文链接:https://www.haomeiwen.com/subject/chimkltx.html