Update HOC props with typing (no any) (#602)

This commit is contained in:
Jaco Greeff 2019-01-14 16:49:39 +01:00 committed by GitHub
parent 28097c9a08
commit 309da4204b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 11 deletions

View File

@ -5,6 +5,10 @@
import { SubmittableExtrinsicFunction } from '@polkadot/api/promise/types';
import ApiPromise from '@polkadot/api/promise';
// helpers for HOC props
export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
export type Subtract<T, K> = Omit<T, keyof K>;
export type BareProps = {
className?: string,
style?: { [index: string]: any }

View File

@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ApiProps } from '../types';
import { ApiProps, Subtract } from '../types';
import { DefaultProps } from './types';
import React from 'react';
@ -11,7 +11,7 @@ import { assert } from '@polkadot/util';
import { ApiConsumer } from '../ApiContext';
export default function withApi <T, P extends ApiProps> (Inner: React.ComponentType<P>, defaultProps: DefaultProps<T> = {}): React.ComponentType<any> {
return class WithApi extends React.PureComponent<any> {
return class WithApi extends React.PureComponent<Subtract<P, ApiProps>> {
constructor (props: any) {
super(props);

View File

@ -2,8 +2,6 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// TODO: Lots of duplicated code between this and withObservable, surely there is a better way of doing this?
import { ApiProps, RxProps } from '../types';
import { HOC, Options } from './types';
@ -26,20 +24,16 @@ type State<T> = RxProps<T> & {
timerId: number
};
type Props = ApiProps & {};
const NOOP = () => {
// ignore
};
// FIXME proper types for attributes
export default function withCall<T, P> (endpoint: string, { at, atProp, rxChange, params = [], paramProp = 'params', propName, transform = echoTransform }: Options<T> = {}): HOC<T> {
export default function withCall<T, P extends ApiProps> (endpoint: string, { at, atProp, rxChange, params = [], paramProp = 'params', propName, transform = echoTransform }: Options<T> = {}): HOC<T> {
return (Inner: React.ComponentType<ApiProps>): React.ComponentType<any> => {
class WithPromise extends React.Component<Props, State<T>> {
class WithPromise extends React.Component<P, State<T>> {
state: State<T>;
constructor (props: Props) {
constructor (props: P) {
super(props);
const [area, section, method] = endpoint.split('.');