Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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");

Generated JS code

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");

// Trying to achieve

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

does typescript support @inline functions ? if not whats the best way achieve similar ..

like image 317
invariant Avatar asked May 24 '26 21:05

invariant


1 Answers

does typescript support @inline functions ?

No.

if not whats the best way achieve similar

You will have to write a tool yourself. I would just not worry about it.

Make the tool yourself

Use the TypeScript compiler to find references to functions you want to inline, and then interpolate the function body to that location.

Start: Some compiler docs https://basarat.gitbook.io/typescript/overview

like image 97
basarat Avatar answered May 26 '26 14:05

basarat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!