Remove as unknown (#1636)

* Remove some as unknowns

* Rename sanitize

* Remove file
This commit is contained in:
Amaury Martiny
2019-12-04 12:19:37 +01:00
committed by Jaco Greeff
parent b7ba654e48
commit f78bf9dde1
14 changed files with 28 additions and 28 deletions
@@ -28,7 +28,7 @@ export function referendumVotesFor (api: ApiInterfaceRx): (referendumId: BN | nu
accountId,
balance: balances[index].votingBalance || createType(api.registry, 'Balance'),
vote: votes[index] || createType(api.registry, 'Vote')
} as unknown as DerivedReferendumVote))
} as DerivedReferendumVote))
)
));
}
+6 -6
View File
@@ -199,10 +199,10 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
}
return section;
}, {} as unknown as DecoratedRpcSection<ApiType, RpcInterface[typeof sectionName]>);
}, {} as DecoratedRpcSection<ApiType, RpcInterface[typeof sectionName]>);
return out;
}, {} as unknown as DecoratedRpc<ApiType, RpcInterface>);
}, {} as DecoratedRpc<ApiType, RpcInterface>);
}
protected decorateMulti<ApiType extends ApiTypes> (decorateMethod: DecorateMethod<ApiType>): QueryableStorageMulti<ApiType> {
@@ -223,10 +223,10 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
out[name] = this.decorateExtrinsicEntry(method, creator);
return out;
}, {} as unknown as SubmittableModuleExtrinsics<ApiType>);
}, {} as SubmittableModuleExtrinsics<ApiType>);
return out;
}, creator as unknown as SubmittableExtrinsics<ApiType>);
}, creator as SubmittableExtrinsics<ApiType>);
}
private decorateExtrinsicEntry<ApiType extends ApiTypes> (method: CallFunction, creator: (value: Call | Uint8Array | string) => SubmittableExtrinsic<ApiType>): SubmittableExtrinsicFunction<ApiType> {
@@ -242,10 +242,10 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
out[name] = this.decorateStorageEntry(method, decorateMethod);
return out;
}, {} as unknown as QueryableModuleStorage<ApiType>);
}, {} as QueryableModuleStorage<ApiType>);
return out;
}, {} as unknown as QueryableStorage<ApiType>);
}, {} as QueryableStorage<ApiType>);
}
private decorateStorageEntry<ApiType extends ApiTypes> (creator: StorageEntry, decorateMethod: DecorateMethod<ApiType>): QueryableStorageEntry<ApiType> {
+1 -1
View File
@@ -28,7 +28,7 @@ describe('ApiPromise', (): void => {
const metadata: any = {};
const key = `${genesisHash}-${specVersion}`;
metadata[key] = rpcData;
const api = await ApiPromise.create({ provider, metadata, registry } as unknown as ApiOptions);
const api = await ApiPromise.create({ provider, metadata, registry } as ApiOptions);
expect(api.genesisHash).toBeDefined();
expect(api.runtimeMetadata).toBeDefined();
+1 -1
View File
@@ -174,7 +174,7 @@ export default function createClass <ApiType extends ApiTypes> ({ api, apiType,
genesisHash: this._api.genesisHash,
runtimeVersion: this._api.runtimeVersion,
version: this._api.extrinsicType
} as unknown as SignatureOptions;
} as SignatureOptions;
}
private _makeEraOptions (options: Partial<SignerOptions>, { header, nonce }: { header: Header | null; nonce: Index }): SignatureOptions {
@@ -39,7 +39,7 @@ export default function fromMetadata (registry: Registry, metadata: Metadata): S
}, { metaVersion: metadata.version });
return newModule;
}, {} as unknown as ModuleStorage);
}, {} as ModuleStorage);
return result;
}, { ...getStorage(registry, metadata.version) });
@@ -24,7 +24,7 @@ function createRuntimeFunction (method: string, key: string, { documentation, ty
modifier: createType(registry, 'StorageEntryModifierLatest', 1), // required
type: createType(registry, 'StorageEntryTypeLatest', type, 0),
toJSON: (): any => key
} as unknown as StorageEntryMetadataLatest,
} as StorageEntryMetadataLatest,
method,
prefix: 'Substrate',
section: 'substrate'
+1 -1
View File
@@ -171,7 +171,7 @@ export default class Rpc implements RpcInterface {
: this.createMethodSend(def);
return exposed;
}, {} as unknown as RpcInterface[Section]);
}, {} as RpcInterface[Section]);
}
private createMethodSend (method: RpcMethod): RpcInterfaceMethod {
@@ -20,31 +20,31 @@ describe('decodeResponse', (): void => {
it('expects a valid jsonrpc field', (): void => {
expect(
(): any => coder.decodeResponse({} as unknown as JsonRpcResponse)
(): any => coder.decodeResponse({} as JsonRpcResponse)
).toThrow(/Invalid jsonrpc/);
});
it('expects a valid id field', (): void => {
expect(
(): any => coder.decodeResponse({ jsonrpc: '2.0' } as unknown as JsonRpcResponse)
(): any => coder.decodeResponse({ jsonrpc: '2.0' } as JsonRpcResponse)
).toThrow(/Invalid id/);
});
it('expects a valid result field', (): void => {
expect(
(): any => coder.decodeResponse({ id: 1, jsonrpc: '2.0' } as unknown as JsonRpcResponse)
(): any => coder.decodeResponse({ id: 1, jsonrpc: '2.0' } as JsonRpcResponse)
).toThrow(/No result/);
});
it('throws any error found', (): void => {
expect(
(): any => coder.decodeResponse({ id: 1, jsonrpc: '2.0', error: { code: 123, message: 'test error' } } as unknown as JsonRpcResponse)
(): any => coder.decodeResponse({ id: 1, jsonrpc: '2.0', error: { code: 123, message: 'test error' } } as JsonRpcResponse)
).toThrow(/123: test error/);
});
it('returns the result', (): void => {
expect(
coder.decodeResponse({ id: 1, jsonrpc: '2.0', result: 'some result' } as unknown as JsonRpcResponse)
coder.decodeResponse({ id: 1, jsonrpc: '2.0', result: 'some result' } as JsonRpcResponse)
).toEqual('some result');
});
});
+1 -1
View File
@@ -75,7 +75,7 @@ export default class Mock implements ProviderInterface {
};
return subs;
}, ({} as unknown as MockStateSubscriptions));
}, ({} as MockStateSubscriptions));
private subscriptionId = 0;
+1 -1
View File
@@ -39,7 +39,7 @@ function extractDef (registry: Registry, _def: Record<string, InterfaceTypes | C
def[key] = Null;
return def;
}, {} as unknown as TypesDef),
}, {} as TypesDef),
isBasic: true
};
}
+6 -6
View File
@@ -37,7 +37,7 @@ export default class Struct<
protected _Types: ConstructorDef;
constructor (registry: Registry, Types: S, value: V | Map<any, any> | any[] | string = {} as unknown as V, jsonMap: Map<keyof S, string> = new Map()) {
constructor (registry: Registry, Types: S, value: V | Map<any, any> | any[] | string = {} as V, jsonMap: Map<keyof S, string> = new Map()) {
const Clazzes = mapToTypeMap(registry, Types);
const decoded: T = Struct.decodeStruct(registry, Clazzes, value, jsonMap);
@@ -75,9 +75,9 @@ export default class Struct<
(raw as any)[key] = values[index];
return raw;
}, {} as unknown as T);
}, {} as T);
} else if (!value) {
return {} as unknown as T;
return {} as T;
}
// We assume from here that value is a JS object (Array, Map, Object)
@@ -114,7 +114,7 @@ export default class Struct<
}
return raw;
}, {} as unknown as T);
}, {} as T);
}
public static with<S extends TypesDef> (Types: S): Constructor<Struct<S>> {
@@ -162,7 +162,7 @@ export default class Struct<
(result as any)[key] = new Type(this.registry).toRawType();
return result;
}, {} as unknown as E);
}, {} as E);
}
/**
@@ -240,7 +240,7 @@ export default class Struct<
result[key] = new Type(registry).toRawType();
return result;
}, {} as unknown as Record<string, string>);
}, {} as Record<string, string>);
}
/**
@@ -73,7 +73,7 @@ function _decodeFixedVec (value: TypeDef, type: string, _: string): TypeDef {
// as a first round, only u8 via u8aFixed, we can add more support
assert(vecLen <= 256, `${type}: Only support for [Type; <length>], where length <= 256`);
value.ext = { length: vecLen, type: vecType } as unknown as TypeDefExtVecFixed;
value.ext = { length: vecLen, type: vecType } as TypeDefExtVecFixed;
return value;
}
+1 -1
View File
@@ -201,7 +201,7 @@ function _removeWrap (_check: string): Mapper {
};
}
export default function santize (value: string): string {
export default function sanitize (value: string): string {
return mappings.reduce((result, fn): string => {
return fn(result);
}, value).trim();
+1 -1
View File
@@ -129,7 +129,7 @@ export default class Call extends Struct implements IMethod {
result[name.toString()] = Type;
return result;
}, {} as unknown as ArgsDef);
}, {} as ArgsDef);
}
/**