Typescript 编译器有 @inline 函数选项吗?

inv*_*ant 9 typescript typescript2.0

 //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");
Run Code Online (Sandbox Code Playgroud)

生成的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");
Run Code Online (Sandbox Code Playgroud)

// 试图实现

var d = createElement("div",{ id: "hello" },"welcome to TS") 
Run Code Online (Sandbox Code Playgroud)

TypeScript 支持 @inline 函数吗?如果不是,实现类似目标的最佳方法是什么..

bas*_*rat 8

TypeScript 支持 @inline 函数吗?

不。

如果不是,实现类似目标的最佳方法是什么

您必须自己编写一个工具。我只是不担心而已。

自己制作工具

使用 TypeScript 编译器查找要内联的函数的引用,然后将函数体插入到该位置。

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