refactor(core): update `noSideEffects()` to return the result of the inner function (#35769)

This is useful for propagating return values without them being converted to a string. It still provides the same guarantees to Closure, which will assume that the function invoked is pure and can be tree-shaken accordingly.

PR Close #35769
This commit is contained in:
Doug Parker 2020-02-21 11:08:59 -08:00 committed by atscott
parent 47a1811e0b
commit 4052dd8188
1 changed files with 3 additions and 3 deletions

View File

@ -15,6 +15,6 @@
* to something which is retained otherwise the call to `noSideEffects` will be removed by closure
* compiler.
*/
export function noSideEffects(fn: () => void): string {
return '' + {toString: fn};
}
export function noSideEffects<T>(fn: () => T): T {
return {toString: fn}.toString() as unknown as T;
}