Improved internal typings

This commit is contained in:
Alexander Cerutti
2019-06-15 19:05:32 +02:00
parent 7c0a667a3c
commit 978b5699ce

View File

@@ -25,6 +25,11 @@ interface PassIndexSignature {
[key: string]: any; [key: string]: any;
} }
export interface PassWithBarcodeMethods extends Pass {
backward: (format: schema.BarcodeFormat) => Pass;
autocomplete: () => Pass;
}
export class Pass implements PassIndexSignature { export class Pass implements PassIndexSignature {
// private model: string; // private model: string;
private bundle: schema.BundleUnit; private bundle: schema.BundleUnit;
@@ -193,7 +198,7 @@ export class Pass implements PassIndexSignature {
* @returns {this} * @returns {this}
*/ */
expiration(date: Date) { expiration(date: Date): this {
if (!(date instanceof Date)) { if (!(date instanceof Date)) {
return this; return this;
} }
@@ -287,7 +292,7 @@ export class Pass implements PassIndexSignature {
* @return {this} Improved this with length property and other methods * @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 = ( const isFirstParameterValid = (
first && ( first && (
typeof first === "string" && first.length || ( typeof first === "string" && first.length || (
@@ -373,7 +378,7 @@ export class Pass implements PassIndexSignature {
* @returns {this} Improved this, with length property and retroCompatibility method. * @returns {this} Improved this, with length property and retroCompatibility method.
*/ */
[barcodesFillMissing]() { [barcodesFillMissing](): this {
const props = this._props["barcodes"]; const props = this._props["barcodes"];
if (props.length === 4 || !props.length) { if (props.length === 4 || !props.length) {
@@ -433,11 +438,11 @@ export class Pass implements PassIndexSignature {
* Sets nfc fields in properties * Sets nfc fields in properties
* *
* @method nfc * @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} * @returns {this}
*/ */
nfc(data: schema.NFC) { nfc(data: schema.NFC): this {
if (!(typeof data === "object" && !Array.isArray(data) && schema.isValid(data, "nfcDict"))) { if (!(typeof data === "object" && !Array.isArray(data) && schema.isValid(data, "nfcDict"))) {
genericDebug("Invalid NFC data provided"); genericDebug("Invalid NFC data provided");
return this; return this;