DypyScript编译器具有@inline函数选项


 //ts code
function div(props?: { id?: String; style?: any }) {
      return function(...children: ReactNode[]) {
        return createElement("div", props, ...children);
      };
    }
const d = div({ id: "hello" })("welcome to TS");

生成的JS代码

function div(props) {
    return function () {
        var children = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            children[_i] = arguments[_i];
        }
        return createElement("div",props,...);
    };
}
var d = div({ id: "hello" })("welcome to TS");

//尝试实现

var d = createElement("div",{ id: "hello" },"welcome to TS") 

打字稿支持@inline功能吗?如果不是什么,最好的方法是实现类似的方法。

打字稿支持@inline功能?

no。

如果不是最好的方法,那么实现类似的方法

您将必须自己写一个工具。我只是不用担心。

自己制作工具

使用打字稿编译器查找您要内联函数的引用,然后将功能正文插入该位置。

开始:一些编译器文档https://basarat.gitbook.io/typescript/overview

最新更新