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
This commit is contained in:
John Knox
2020-05-07 10:17:03 -07:00
committed by Facebook GitHub Bot
parent f00cd2964e
commit 9534cafb17

View File

@@ -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<any>;
// 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<boolean>;
}