打字稿编译器有@inline函数选项吗?
does typescript compiler has @inline function option ?
//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")
typescript 支持@inline 函数吗?如果不是,最好的方法是什么?
does typescript support @inline functions ?
没有。
if not whats the best way achieve similar
你将不得不自己编写一个工具。我只是不担心它。
自己制作工具
使用 TypeScript 编译器查找对要内联的函数的引用,然后将函数体插入到该位置。
开始:一些编译器文档https://basarat.gitbooks.io/typescript/content/docs/compiler/overview.html
//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")
typescript 支持@inline 函数吗?如果不是,最好的方法是什么?
does typescript support @inline functions ?
没有。
if not whats the best way achieve similar
你将不得不自己编写一个工具。我只是不担心它。
自己制作工具
使用 TypeScript 编译器查找对要内联的函数的引用,然后将函数体插入到该位置。
开始:一些编译器文档https://basarat.gitbooks.io/typescript/content/docs/compiler/overview.html