Search code examples
typescriptv8

Typescript v8 natives syntax Expression expected


Using Typescript 4.1.2 is it possible to compile code that references the functions one calls when the --allow-natives-syntax flag in v8 is set?

For example:

function foo(bar: ()=>void)): void {
    %OptimizeFunctionOnNextCall(bar); // --> TS1109; Expression expected
}

Neither //@ts-ignore nor //@ts-expect-error silence this error


Solution

  • I don't have boilerplate to test v8 natives, so I don't know if it works, but You can try next piece of code

    function foo(bar: () => void): void {
      //@ts-ignore
      ((void 0) %OptimizeFunctionOnNextCall(bar));
    }
    

    Don't judge me) I'm just trying to help)