From 4052dd8188bfc18859ce211d8ad40fb471297359 Mon Sep 17 00:00:00 2001 From: Doug Parker Date: Fri, 21 Feb 2020 11:08:59 -0800 Subject: [PATCH] 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 --- packages/core/src/util/closure.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/core/src/util/closure.ts b/packages/core/src/util/closure.ts index de36d31b0d..19368bc807 100644 --- a/packages/core/src/util/closure.ts +++ b/packages/core/src/util/closure.ts @@ -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}; -} \ No newline at end of file +export function noSideEffects(fn: () => T): T { + return {toString: fn}.toString() as unknown as T; +}