From c822d908225b67cfefe8adb3c2d933604b880b3f Mon Sep 17 00:00:00 2001 From: Alexander von Weiss Date: Wed, 13 Jun 2018 14:56:50 +0200 Subject: [PATCH] validate and extend typings by testing it against runtime --- index.d.ts | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/index.d.ts b/index.d.ts index d6b8746..9921d49 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,8 +1,16 @@ namespace Receptacle { - export interface Options { - id?: string; + export interface Options { + id?: number|string; max?: number; - items?: any[]; + items?: Items[]; + lastModified?: Date; + } + + export interface Export { + id: number|string; + max: number|undefined; + items: (Items & InternalItemData)[]; + lastModified: Date; } export interface SetOptions { @@ -10,21 +18,33 @@ namespace Receptacle { refresh?: boolean; meta?: X; } + + export interface InternalItemData { + meta: X|undefined; + refresh: number|undefined; + expires: number|undefined; + } + + export interface Items { + key: string; + value: T; + } } class Receptacle { - constructor(options?: Receptacle.Options); - public id: string; + constructor(options?: Receptacle.Options); + public id: number|string; public max: number; - public items: T[]; + public items: Receptacle.Items[]; public size: number; public has(key: string): boolean; - public get(key: string): T; - public meta(key: string): X; - public set(key: string, value: T, options?: Receptacle.SetOptions): void; + public get(key: string): T|null; + public meta(key: string): X|undefined; + public set(key: string, value: T, options?: Receptacle.SetOptions): Receptacle; public delete(key: string): void; public expire(key: string, ms: number = 0): void; public clear(): void; + public toJSON(): Receptacle.Export; } export = Receptacle;