Open lyricnz opened 8 months ago
FWIW, using a generic that provides a concrete return-type:
async function paginateAwsCallT<T>(paginatorRef: any, client: any, what: string, params?: any): Promise<T[]> {
const parameters = params || {};
const paginator = paginatorRef({ client: client }, parameters);
const entityList: T[] = [];
for await (const page of paginator) {
entityList.push(...page[what]);
}
return entityList;
}
This creates numerous errors with optional fields:
drivers/ec2.ts:198:46 - error TS18048: 'xi' is possibly 'undefined'.
198 if (inoperableStates.find((x) => x === xi.State.Name)) {
~~
drivers/ec2.ts:198:46 - error TS18048: 'xi.State' is possibly 'undefined'.
198 if (inoperableStates.find((x) => x === xi.State.Name)) {
~~~~~~~~
As well as errors when the result items have arbitrary data added to them (eg: adding instanceDetails to Volume, adding AutoScalingGroupName to Instances, etc)
const accounts = await paginateAwsCallT<Account>(paginateListAccounts, client, 'Accounts');
accounts.forEach((account) => {
account.accountId = account.Id;
lib/config.ts:57:19 - error TS2339: Property 'accountId' does not exist on type 'Account'.
57 account.accountId = account.Id;
@abukharov @alutman-innablr is there any value in this? Or leave it loosey-goosey?
FWIW, this lack of type-safety hid a little bug where InstrumentedEc2() was constructed with a CreateVolumeCommandOutput
rather than an Instance
.
https://github.com/Innablr/revolver/blob/develop/lib/common.ts#L1
@alutman-innablr