eslint cleanup (as unknown as State -> Pick<State, never>) (#1405)

This commit is contained in:
Jaco Greeff 2019-07-15 12:36:17 +02:00 committed by GitHub
parent 073eb9f86f
commit ea829237de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 76 additions and 84 deletions

View File

@ -127,35 +127,27 @@ class Account extends React.PureComponent<Props> {
}
private toggleBackup = (): void => {
const { isBackupOpen } = this.state;
this.setState({
this.setState(({ isBackupOpen }: State): Pick<State, never> => ({
isBackupOpen: !isBackupOpen
});
}));
}
private toggleForget = (): void => {
const { isForgetOpen } = this.state;
this.setState({
this.setState(({ isForgetOpen }: State): Pick<State, never> => ({
isForgetOpen: !isForgetOpen
});
}));
}
private togglePass = (): void => {
const { isPasswordOpen } = this.state;
this.setState({
this.setState(({ isPasswordOpen }: State): Pick<State, never> => ({
isPasswordOpen: !isPasswordOpen
});
}));
}
private toggleTransfer = (): void => {
const { isTransferOpen } = this.state;
this.setState({
this.setState(({ isTransferOpen }: State): Pick<State, never> => ({
isTransferOpen: !isTransferOpen
});
}));
}
private onForget = (): void => {

View File

@ -107,15 +107,15 @@ class Overview extends React.PureComponent<Props, State> {
}
private toggleCreate = (): void => {
this.setState(({ isCreateOpen }): State => ({
this.setState(({ isCreateOpen }): Pick<State, never> => ({
isCreateOpen: !isCreateOpen
}) as unknown as State);
}));
}
private toggleImport = (): void => {
this.setState(({ isImportOpen }): State => ({
this.setState(({ isImportOpen }): Pick<State, never> => ({
isImportOpen: !isImportOpen
}) as unknown as State);
}));
}
}

View File

@ -101,15 +101,15 @@ class Address extends React.PureComponent<Props, State> {
}
private toggleForget = (): void => {
this.setState(({ isForgetOpen }): State => ({
this.setState(({ isForgetOpen }): Pick<State, never> => ({
isForgetOpen: !isForgetOpen
}) as unknown as State);
}));
}
private toggleTransfer = (): void => {
this.setState(({ isTransferOpen }): State => ({
this.setState(({ isTransferOpen }): Pick<State, never> => ({
isTransferOpen: !isTransferOpen
}) as unknown as State);
}));
}
private onForget = (): void => {

View File

@ -97,7 +97,7 @@ class Upload extends ContractModal<Props, State> {
private onSuccess = (result: SubmittableResult): void => {
const { api } = this.props;
this.setState(({ abi, name, tags }): State | null => {
this.setState(({ abi, name, tags }): Pick<State, never> | null => {
const section = api.tx.contracts ? 'contracts' : 'contract';
const record = result.findRecord(section, 'CodeStored');
@ -115,7 +115,7 @@ class Upload extends ContractModal<Props, State> {
});
}
return { isBusy: false } as unknown as State;
return { isBusy: false };
});
}
}

View File

@ -49,14 +49,14 @@ class Call extends TxComponent<Props, State> {
public state: State = this.defaultState;
public static getDerivedStateFromProps ({ address: propsAddress, method: propsMethod, isOpen }: Props, { address, method }: State): State | null {
public static getDerivedStateFromProps ({ address: propsAddress, method: propsMethod, isOpen }: Props, { address, method }: State): Pick<State, never> | null {
if (!isOpen) {
return {
address: null,
method: null,
contractAbi: null,
isAddressValid: false
} as unknown as State;
};
}
return {
@ -74,7 +74,7 @@ class Call extends TxComponent<Props, State> {
? { method: propsMethod }
: {}
)
} as unknown as State;
};
}
public render (): React.ReactNode {
@ -113,10 +113,10 @@ class Call extends TxComponent<Props, State> {
}
const methodOptions = contractAbi
? Object.keys(contractAbi.messages).map((key) => {
? Object.keys(contractAbi.messages).map((key): { key: string; text: string; value: string } => {
const fn = contractAbi.messages[key];
const type = fn.type ? `: ${fn.type}` : '';
const args = fn.args.map(({ name, type }) => `${name}: ${type}`);
const args = fn.args.map(({ name, type }): string => `${name}: ${type}`);
const text = `${key}(${args.join(', ')})${type}`;
return {
@ -276,13 +276,13 @@ class Call extends TxComponent<Props, State> {
}
private toggleBusy = (): void => {
this.setState(({ isBusy }): State => ({
this.setState(({ isBusy }): Pick<State, never> => ({
isBusy: !isBusy
}) as unknown as State);
}));
}
private reset = (): void => {
this.setState((state: State): State => {
this.setState((state: State): Pick<State, never> => {
if (!state.isBusy) {
return {
...state,
@ -290,7 +290,7 @@ class Call extends TxComponent<Props, State> {
};
}
return {} as unknown as State;
return {};
});
}

View File

@ -14,7 +14,7 @@ import { Abi } from '@polkadot/api-contract';
import { withApi, withMulti } from '@polkadot/ui-api';
import keyring from '@polkadot/ui-keyring';
import { Button, Dropdown, InputBalance, TxButton } from '@polkadot/ui-app';
import { AccountId, getTypeDef } from '@polkadot/types';
import { AccountId, TypeDef, getTypeDef } from '@polkadot/types';
import createValues from '@polkadot/ui-params/values';
import ContractModal, { ContractModalProps, ContractModalState } from './Modal';
@ -70,7 +70,7 @@ class Deploy extends ContractModal<Props, State> {
const { codeHash, constructOptions, contractAbi, endowment, isAbiSupplied, isBusy, isHashValid } = this.state;
const isEndowValid = !endowment.isZero();
const codeOptions = store.getAllCode().map(({ json: { codeHash, name } }) => ({
const codeOptions = store.getAllCode().map(({ json: { codeHash, name } }): { text: string; value: string } => ({
text: `${name} (${codeHash})`,
value: codeHash
}));
@ -179,7 +179,7 @@ class Deploy extends ContractModal<Props, State> {
contractAbi,
isAbiValid: !!contractAbi,
params: createValues(
contractAbi.deploy.args.map(({ name, type }) => ({
contractAbi.deploy.args.map(({ name, type }): { type: TypeDef } => ({
type: getTypeDef(type, name)
}))
)
@ -196,7 +196,7 @@ class Deploy extends ContractModal<Props, State> {
}
}
private getCodeState = (codeHash: string | null = null): State => {
private getCodeState = (codeHash: string | null = null): Pick<State, never> => {
if (codeHash) {
const code = store.getCode(codeHash);
@ -210,11 +210,11 @@ class Deploy extends ContractModal<Props, State> {
isHashValid: true,
isNameValid: true,
...this.getContractAbiState(json.abi, contractAbi)
} as unknown as State;
};
}
}
return {} as unknown as State;
return {};
}
private constructCall = (): any[] => {
@ -256,7 +256,7 @@ class Deploy extends ContractModal<Props, State> {
if (record) {
const address = record.event.data[1] as unknown as AccountId;
this.setState(({ abi, name, tags }): State | unknown => {
this.setState(({ abi, name, tags }): Pick<State, never> | unknown => {
if (!abi || !name) {
return;
}
@ -274,7 +274,7 @@ class Deploy extends ContractModal<Props, State> {
this.onClose();
return { isBusy: false } as unknown as State;
return { isBusy: false };
});
}
}

View File

@ -38,7 +38,7 @@ export default class Params extends React.PureComponent<Props, State> {
name,
type: getTypeDef(type, name)
}))
} as unknown as State;
};
}
public render (): React.ReactNode {

View File

@ -51,12 +51,12 @@ class App extends React.PureComponent<Props, State> {
});
}
public static getDerivedStateFromProps ({ contracts }: Props): State {
public static getDerivedStateFromProps ({ contracts }: Props): Pick<State, never> {
const hasContracts = !!contracts && Object.keys(contracts).length >= 1;
return {
hasContracts
} as unknown as State;
};
}
public render (): React.ReactNode {

View File

@ -21,7 +21,7 @@ interface Props extends I18nProps {
interface State {
accountId?: string;
isVotingOpen: boolean;
voteOptions: { text: React.ReactNode, value: boolean }[];
voteOptions: { text: React.ReactNode; value: boolean }[];
voteValue: boolean;
}
@ -65,7 +65,7 @@ class Voting extends React.PureComponent<Props, State> {
);
}
private renderModal () {
private renderModal (): React.ReactNode {
const { referendumId, t } = this.props;
const { accountId, isVotingOpen, voteOptions, voteValue } = this.state;
@ -128,9 +128,9 @@ class Voting extends React.PureComponent<Props, State> {
}
private toggleVoting = (): void => {
this.setState(({ isVotingOpen }): State => ({
this.setState(({ isVotingOpen }): Pick<State, never> => ({
isVotingOpen: !isVotingOpen
}) as unknown as State);
}));
}
}

View File

@ -81,7 +81,7 @@ class Account extends React.PureComponent<Props, State> {
stashId: null
};
public static getDerivedStateFromProps ({ accountId, staking_info }: Props): State | null {
public static getDerivedStateFromProps ({ accountId, staking_info }: Props): Pick<State, never> | null {
if (!staking_info) {
return null;
}
@ -102,7 +102,7 @@ class Account extends React.PureComponent<Props, State> {
stakingLedger,
stashId: toIdString(stashId),
validatorPrefs
} as unknown as State;
};
}
public render (): React.ReactNode {
@ -526,51 +526,51 @@ class Account extends React.PureComponent<Props, State> {
}
private toggleBondExtra = (): void => {
this.setState(({ isBondExtraOpen }): State => ({
this.setState(({ isBondExtraOpen }): Pick<State, never> => ({
isBondExtraOpen: !isBondExtraOpen
}) as unknown as State);
}));
}
private toggleNominate = (): void => {
this.setState(({ isNominateOpen }): State => ({
this.setState(({ isNominateOpen }): Pick<State, never> => ({
isNominateOpen: !isNominateOpen
}) as unknown as State);
}));
}
private toggleSetControllerAccount = (): void => {
this.setState(({ isSetControllerAccountOpen }): State => ({
this.setState(({ isSetControllerAccountOpen }): Pick<State, never> => ({
isSetControllerAccountOpen: !isSetControllerAccountOpen
}) as unknown as State);
}));
}
private toggleSetRewardDestination = (): void => {
this.setState(({ isSetRewardDestinationOpen }): State => ({
this.setState(({ isSetRewardDestinationOpen }): Pick<State, never> => ({
isSetRewardDestinationOpen: !isSetRewardDestinationOpen
}) as unknown as State);
}));
}
private toggleSetSessionAccount = (): void => {
this.setState(({ isSetSessionAccountOpen }): State => ({
this.setState(({ isSetSessionAccountOpen }): Pick<State, never> => ({
isSetSessionAccountOpen: !isSetSessionAccountOpen
}) as unknown as State);
}));
}
private toggleSettingPopup = (): void => {
this.setState(({ isSettingPopupOpen }): State => ({
this.setState(({ isSettingPopupOpen }): Pick<State, never> => ({
isSettingPopupOpen: !isSettingPopupOpen
}) as unknown as State);
}));
}
private toggleUnbond = (): void => {
this.setState(({ isUnbondOpen }): State => ({
this.setState(({ isUnbondOpen }): Pick<State, never> => ({
isUnbondOpen: !isUnbondOpen
}) as unknown as State);
}));
}
private toggleValidate = (): void => {
this.setState(({ isValidateOpen }): State => ({
this.setState(({ isValidateOpen }): Pick<State, never> => ({
isValidateOpen: !isValidateOpen
}) as unknown as State);
}));
}
}

View File

@ -55,7 +55,7 @@ class Address extends React.PureComponent<Props, State> {
};
}
public static getDerivedStateFromProps ({ staking_info }: Props, prevState: State): State | null {
public static getDerivedStateFromProps ({ staking_info }: Props, prevState: State): Pick<State, never> | null {
if (!staking_info) {
return null;
}
@ -73,7 +73,7 @@ class Address extends React.PureComponent<Props, State> {
stashTotal: stakingLedger
? formatBalance(stakingLedger.total)
: prevState.stashTotal
} as unknown as State;
};
}
public render (): React.ReactNode {

View File

@ -65,7 +65,7 @@ class App extends React.PureComponent<Props, State> {
};
}
public static getDerivedStateFromProps ({ allStashesAndControllers = [[], []], currentValidatorsControllersV1OrStashesV2 = [], staking_recentlyOffline = [] }: Props): State {
public static getDerivedStateFromProps ({ allStashesAndControllers = [[], []], currentValidatorsControllersV1OrStashesV2 = [], staking_recentlyOffline = [] }: Props): Pick<State, never> {
return {
allControllers: allStashesAndControllers[1].filter((optId): boolean => optId.isSome).map((accountId): string =>
accountId.unwrap().toString()
@ -89,7 +89,7 @@ class App extends React.PureComponent<Props, State> {
return result;
}, {} as unknown as RecentlyOfflineMap)
} as unknown as State;
};
}
public render (): React.ReactNode {

View File

@ -58,8 +58,8 @@ export default class LabelHelp extends React.PureComponent<Props, State> {
}
private toggleTooltip = (): void => {
this.setState(({ tooltipOpen }): State => ({
this.setState(({ tooltipOpen }): Pick<State, never> => ({
tooltipOpen: !tooltipOpen
}) as unknown as State);
}));
}
}

View File

@ -95,9 +95,9 @@ export default class EnumParam extends React.PureComponent<Props, State> {
}
private onChange = (value: string): void => {
this.setState(({ sub }): State => ({
this.setState(({ sub }): Pick<State, never> => ({
def: sub.find(({ name }): boolean => name === value) || null
}) as unknown as State);
}));
}
private onChangeParam = ([{ isValid, value }]: RawParam[]): void => {

View File

@ -111,13 +111,13 @@ class Vector extends React.PureComponent<Props, State> {
private onChange = (index: number): (value: RawParam) => void => {
return (value: RawParam): void => {
this.setState(
({ values }: State): State => ({
({ values }: State): Pick<State, never> => ({
values: values.map((svalue, sindex): RawParam =>
(sindex === index)
? value
: svalue
)
} as unknown as State),
}),
(): void => {
const { values } = this.state;
const { onChange } = this.props;
@ -132,7 +132,7 @@ class Vector extends React.PureComponent<Props, State> {
}
private rowAdd = (): void => {
this.setState(({ values }: State, { type: { sub } }: Props): State => {
this.setState(({ values }: State, { type: { sub } }: Props): Pick<State, never> => {
const value = getInitValue(sub as TypeDef);
return {
@ -140,14 +140,14 @@ class Vector extends React.PureComponent<Props, State> {
isValid: !isUndefined(value),
value
})
} as unknown as State;
};
});
}
private rowRemove = (): void => {
this.setState(({ values }: State): State => ({
this.setState(({ values }: State): Pick<State, never> => ({
values: values.slice(0, values.length - 1)
} as unknown as State));
}));
}
}

View File

@ -126,7 +126,7 @@ class Params extends React.PureComponent<Props, State> {
const { isValid = false, value } = newValue;
this.setState(
(prevState: State): State => ({
(prevState: State): Pick<State, never> => ({
values: (prevState.values || []).map((prev, index): RawParam =>
index !== at
? prev
@ -135,7 +135,7 @@ class Params extends React.PureComponent<Props, State> {
value
}
)
} as unknown as State),
}),
this.triggerUpdate
);
}