From 978b5699cea35025eb824cc8a79ebe02378d227a Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Sat, 15 Jun 2019 19:05:32 +0200 Subject: [PATCH] Improved internal typings --- src/pass.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/pass.ts b/src/pass.ts index 9069b32..debec20 100644 --- a/src/pass.ts +++ b/src/pass.ts @@ -25,6 +25,11 @@ interface PassIndexSignature { [key: string]: any; } +export interface PassWithBarcodeMethods extends Pass { + backward: (format: schema.BarcodeFormat) => Pass; + autocomplete: () => Pass; +} + export class Pass implements PassIndexSignature { // private model: string; private bundle: schema.BundleUnit; @@ -193,7 +198,7 @@ export class Pass implements PassIndexSignature { * @returns {this} */ - expiration(date: Date) { + expiration(date: Date): this { if (!(date instanceof Date)) { return this; } @@ -287,7 +292,7 @@ export class Pass implements PassIndexSignature { * @return {this} Improved this with length property and other methods */ - barcode(first: string | schema.Barcode, ...data: schema.Barcode[]): this { + barcode(first: string | schema.Barcode, ...data: schema.Barcode[]): PassWithBarcodeMethods { const isFirstParameterValid = ( first && ( typeof first === "string" && first.length || ( @@ -373,7 +378,7 @@ export class Pass implements PassIndexSignature { * @returns {this} Improved this, with length property and retroCompatibility method. */ - [barcodesFillMissing]() { + [barcodesFillMissing](): this { const props = this._props["barcodes"]; if (props.length === 4 || !props.length) { @@ -433,11 +438,11 @@ export class Pass implements PassIndexSignature { * Sets nfc fields in properties * * @method nfc - * @params {Object} data - the data to be pushed in the pass + * @params data - the data to be pushed in the pass * @returns {this} */ - nfc(data: schema.NFC) { + nfc(data: schema.NFC): this { if (!(typeof data === "object" && !Array.isArray(data) && schema.isValid(data, "nfcDict"))) { genericDebug("Invalid NFC data provided"); return this;