From 9534cafb17816e5005f0275e160433a4a0b33ebe Mon Sep 17 00:00:00 2001 From: John Knox Date: Thu, 7 May 2020 10:17:03 -0700 Subject: [PATCH] Fix type of params in client.send and client.call Summary: Fixes https://github.com/facebook/flipper/issues/1142 When using `client.call(methodName, params)`, params has to be an object, not, for example a string. It may work on some client implementations, e.g. iOS, but this is a coincidence and not to be relied on. If this gives you new type errors, the plugin should continue to run in the short term but has no guarantees, please adapt it to conform. You can do this by preserving backwards compatibility by doing a typecheck in your client plugin if necessary. CHANGELOG: Calling `client.call()` or `client.send()` now fails to type-check if params is not an object, to match client implementations. Reviewed By: nikoant Differential Revision: D21450694 fbshipit-source-id: 53db49f874838769e39a94b1c4bd4c0b30ecdbc7 --- desktop/app/src/plugin.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/desktop/app/src/plugin.tsx b/desktop/app/src/plugin.tsx index ebd240dc8..bac0aa3e7 100644 --- a/desktop/app/src/plugin.tsx +++ b/desktop/app/src/plugin.tsx @@ -20,7 +20,7 @@ import {Idler} from './utils/Idler'; import {StaticView} from './reducers/connections'; import {State as ReduxState} from './reducers'; import {DEFAULT_MAX_QUEUE_SIZE} from './reducers/pluginMessageQueue'; -type Parameters = any; +type Parameters = {[key: string]: any}; // This function is intended to be called from outside of the plugin. // If you want to `call` from the plugin use, this.client.call @@ -46,7 +46,7 @@ export interface PluginClient { // eslint-disable-next-line call(method: string, params?: Parameters): Promise; // eslint-disable-next-line - subscribe(method: string, callback: (params: Parameters) => void): void; + subscribe(method: string, callback: (params: any) => void): void; // eslint-disable-next-line supportsMethod(method: string): Promise; }