Improve typing around wrapInMatrixClientContext (#8130)

This commit is contained in:
Robin 2022-03-23 18:13:40 -04:00 committed by GitHub
parent 8f1e97be0d
commit 3317b60437
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 11 deletions

View file

@ -14,16 +14,16 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import React, { RefCallback } from "react";
import React, { RefCallback, ComponentType } from "react";
import { MatrixClient } from "matrix-js-sdk/src/matrix";
import { MatrixClientPeg as peg } from '../../src/MatrixClientPeg';
import MatrixClientContext from "../../src/contexts/MatrixClientContext";
type WrapperType<T> = React.Component<{ wrappedRef?: RefCallback<T> }>;
type WrapperProps<T> = { wrappedRef?: RefCallback<ComponentType<T>> } & T;
export function wrapInMatrixClientContext<T>(WrappedComponent): WrapperType<T> {
class Wrapper extends React.Component<{ wrappedRef?: RefCallback<T> }> {
export function wrapInMatrixClientContext<T>(WrappedComponent: ComponentType<T>): ComponentType<WrapperProps<T>> {
class Wrapper extends React.Component<WrapperProps<T>> {
_matrixClient: MatrixClient;
constructor(props) {
super(props);
@ -37,5 +37,5 @@ export function wrapInMatrixClientContext<T>(WrappedComponent): WrapperType<T> {
</MatrixClientContext.Provider>;
}
}
return Wrapper as unknown as WrapperType<T>;
return Wrapper;
}