Improved spaces, types and casting

This commit is contained in:
Alexander Cerutti
2021-06-21 22:06:00 +02:00
parent d35cb627e5
commit da86956583

View File

@@ -40,13 +40,11 @@ export class Pass {
private fieldsKeys: Set<string> = new Set<string>(); private fieldsKeys: Set<string> = new Set<string>();
private passCore: Schemas.ValidPass; private passCore: Schemas.ValidPass;
// Setting these as possibly undefined because we set public headerFields: FieldsArray;
// them all in an loop later public primaryFields: FieldsArray;
public headerFields: FieldsArray | undefined; public secondaryFields: FieldsArray;
public primaryFields: FieldsArray | undefined; public auxiliaryFields: FieldsArray;
public secondaryFields: FieldsArray | undefined; public backFields: FieldsArray;
public auxiliaryFields: FieldsArray | undefined;
public backFields: FieldsArray | undefined;
private Certificates: Schemas.CertificatesSchema; private Certificates: Schemas.CertificatesSchema;
private [transitType]: string = ""; private [transitType]: string = "";
@@ -93,6 +91,7 @@ export class Pass {
const passCoreKeys = Object.keys( const passCoreKeys = Object.keys(
this.passCore, this.passCore,
) as (keyof Schemas.ValidPass)[]; ) as (keyof Schemas.ValidPass)[];
const validatedPassKeys = passCoreKeys.reduce<Schemas.ValidPass>( const validatedPassKeys = passCoreKeys.reduce<Schemas.ValidPass>(
(acc, current) => { (acc, current) => {
if (this.type === current) { if (this.type === current) {
@@ -115,7 +114,11 @@ export class Pass {
currentSchema, currentSchema,
this.passCore[current] as Schemas.ArrayPassSchema[], this.passCore[current] as Schemas.ArrayPassSchema[],
); );
return { ...acc, [current]: valid };
return {
...acc,
[current]: valid,
};
} else { } else {
return { return {
...acc, ...acc,
@@ -195,7 +198,7 @@ export class Pass {
); );
} }
const finalBundle = { ...this.bundle } as Schemas.BundleUnit; const finalBundle: Schemas.BundleUnit = { ...this.bundle };
/** /**
* Iterating through languages and generating pass.string file * Iterating through languages and generating pass.string file
@@ -488,7 +491,7 @@ export class Pass {
return acc; return acc;
} }
return [...acc, validated] as Schemas.Barcode[]; return [...acc, validated];
}, },
[], [],
); );
@@ -669,17 +672,15 @@ function barcodesFromUncompleteData(message: string): Schemas.Barcode[] {
return []; return [];
} }
return [ return (
"PKBarcodeFormatQR", [
"PKBarcodeFormatPDF417", "PKBarcodeFormatQR",
"PKBarcodeFormatAztec", "PKBarcodeFormatPDF417",
"PKBarcodeFormatCode128", "PKBarcodeFormatAztec",
].map( "PKBarcodeFormatCode128",
(format) => ] as Array<Schemas.BarcodeFormat>
Schemas.getValidated( ).map((format) =>
{ format, message }, Schemas.getValidated({ format, message }, Schemas.Barcode),
Schemas.Barcode,
) as Schemas.Barcode,
); );
} }