diff --git a/Makefile b/Makefile index c6f1829..c441dc6 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ TESTS_IN = test/*.test.js # Tools standard = $(BIN)/standard +tsc = $(BIN)/tsc snazzy = $(BIN)/snazzy coveralls = $(BIN)/coveralls istanbul = $(BIN)/istanbul @@ -19,6 +20,10 @@ uglifyjs = $(BIN)/uglifyjs lint: $(standard) --verbose | $(snazzy) +# Run type checking.. +type-check: + $(tsc) + # Save code coverage to coveralls coveralls: cat coverage/lcov.info | $(coveralls) diff --git a/index.d.ts b/index.d.ts index 9921d49..16f9196 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,4 @@ -namespace Receptacle { +declare namespace Receptacle { export interface Options { id?: number|string; max?: number; @@ -31,7 +31,7 @@ namespace Receptacle { } } -class Receptacle { +declare class Receptacle { constructor(options?: Receptacle.Options); public id: number|string; public max: number; @@ -40,9 +40,9 @@ class Receptacle { public has(key: string): boolean; public get(key: string): T|null; public meta(key: string): X|undefined; - public set(key: string, value: T, options?: Receptacle.SetOptions): Receptacle; + public set(key: string, value: T, options?: Receptacle.SetOptions): Receptacle; public delete(key: string): void; - public expire(key: string, ms: number = 0): void; + public expire(key: string, ms?: number): void; public clear(): void; public toJSON(): Receptacle.Export; } diff --git a/package-lock.json b/package-lock.json index 773b512..f8afb9e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -84,6 +84,7 @@ "resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz", "integrity": "sha1-DNkKVhCT810KmSVsIrcGlDP60Rc=", "dev": true, + "optional": true, "requires": { "kind-of": "^3.0.2", "longest": "^1.0.1", @@ -2368,6 +2369,7 @@ "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.1.0.tgz", "integrity": "sha1-R11pil5J/15T0U4+cyQp3Iv0z0c=", "dev": true, + "optional": true, "requires": { "is-buffer": "^1.0.2" } @@ -2475,7 +2477,8 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", "integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=", - "dev": true + "dev": true, + "optional": true }, "loose-envify": { "version": "1.3.1", @@ -3176,7 +3179,8 @@ "version": "1.6.1", "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", "integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=", - "dev": true + "dev": true, + "optional": true }, "request": { "version": "2.87.0", @@ -3724,6 +3728,12 @@ "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", "dev": true }, + "typescript": { + "version": "4.9.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", + "integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", + "dev": true + }, "ua-parser-js": { "version": "0.7.18", "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.18.tgz", diff --git a/package.json b/package.json index 137d212..cf25e91 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "mocha": "^5.2.0", "snazzy": "^7.1.1", "standard": "^11.0.1", + "typescript": "^4.9.5", "uglifyjs": "^2.4.11" }, "files": [ @@ -42,8 +43,9 @@ "build": "make build", "coveralls": "make coveralls", "lint": "make lint", - "test": "npm run lint && make test", - "test-ci": "npm run lint && make test-ci" + "type-check": "make type-check", + "test": "npm run lint && npm run type-check && make test", + "test-ci": "npm run lint && npm run type-check && make test-ci" }, "typings": "./index.d.ts", "standard": { diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..254c7b0 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,3 @@ +{ + "files": ["index.d.ts"] +}