From 9b81def33527f6c11943043212df03d1f565e836 Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Thu, 30 Sep 2021 23:58:29 +0200 Subject: [PATCH] Improved PKPass.from signature and made additionalProps to be never if source is not a PKPass instance --- src/PKPass.ts | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/PKPass.ts b/src/PKPass.ts index 6e16907..5783fc8 100644 --- a/src/PKPass.ts +++ b/src/PKPass.ts @@ -38,13 +38,15 @@ export default class PKPass extends Bundle { * @returns */ - static async from( - source: PKPass | Schemas.Template, - additionalProps: Schemas.OverridablePassProps = {}, + static async from( + source: S, + additionalProps: S extends PKPass + ? Schemas.OverridablePassProps + : never, ): Promise { let certificates: Schemas.CertificatesSchema = undefined; let buffers: Schemas.FileBuffers = undefined; - let overrides: Schemas.OverridablePassProps = {}; + let props: Schemas.OverridablePassProps = {}; if (!source) { throw new TypeError( @@ -85,7 +87,7 @@ export default class PKPass extends Bundle { buffers = await getModelFolderContents(source.model); certificates = source.certificates; - overrides = source.overrides || {}; + props = source.props ?? {}; } if (additionalProps && Object.keys(additionalProps).length) { @@ -95,14 +97,11 @@ export default class PKPass extends Bundle { ); if (validation) { - Object.assign(overrides, validation); + Object.assign(props, validation); } } - return new PKPass(buffers, certificates, { - ...overrides, - ...additionalProps, - }); + return new PKPass(buffers, certificates, props); } /**