Skip to content

Commit 53759d7

Browse files
committed
feat(ts-typings): add typescript definitions
Closes #5
1 parent 6a83b0f commit 53759d7

4 files changed

Lines changed: 80 additions & 3 deletions

File tree

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
"name": "decko",
33
"version": "1.1.3",
44
"main": "decko.js",
5+
"types": "index.d.ts",
56
"description": "A collection of the most useful property decorators.",
67
"scripts": {
7-
"build": "babel -f $npm_package_main -s -o $npm_package_main < src/${npm_package_main}",
8-
"test": "eslint {src,tests}/**.js && mocha --compilers js:babel/register tests/**/*.js",
8+
"build": "babel -f $npm_package_main -s -o $npm_package_main < src/${npm_package_main} && npm run build:ts",
9+
"build:ts": "cp src/decko.d.ts index.d.ts",
10+
"test": "npm run test:ts && eslint {src,tests}/**.js && mocha --compilers js:babel/register tests/**/*.js",
11+
"test:ts": "tsc -p ./",
12+
"style:ts": "tsfmt -r",
913
"prepublish": "npm run build",
1014
"release": "npm run build && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
1115
},
@@ -18,6 +22,8 @@
1822
"babel-eslint": "^4.1.6",
1923
"chai": "^3.2.0",
2024
"eslint": "^1.10.3",
21-
"mocha": "^2.3.0"
25+
"mocha": "^2.3.0",
26+
"typescript": "2.1.6",
27+
"typescript-formatter": "4.1.1"
2228
}
2329
}

src/decko.d.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
*
3+
*/
4+
export function bind<T>(
5+
target: Object,
6+
propertyKey: string | symbol,
7+
descriptor?: TypedPropertyDescriptor<T>
8+
): TypedPropertyDescriptor<T> | void;
9+
export function bind(): MethodDecorator;
10+
11+
/**
12+
* @param caseSensitive Makes cache keys case-insensitive
13+
* @param cache Presupply cache storage, for seeding or sharing entries
14+
*/
15+
16+
export function memoize<T>(
17+
target: Object,
18+
propertyKey: string | symbol,
19+
descriptor?: TypedPropertyDescriptor<T>
20+
): TypedPropertyDescriptor<T> | void;
21+
export function memoize(caseSensitive?: boolean, cache?: Object): MethodDecorator;
22+
/**
23+
* @param delay number
24+
*/
25+
export function debounce<T>(
26+
target: Object,
27+
propertyKey: string | symbol,
28+
descriptor?: TypedPropertyDescriptor<T>
29+
): TypedPropertyDescriptor<T> | void;
30+
export function debounce(delay?: number): MethodDecorator;

tests/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { bind, debounce, memoize } from '..';
2+
class C {
3+
@bind
4+
foo() { }
5+
6+
@debounce
7+
moo() { }
8+
9+
@debounce(1000)
10+
mooWithCustomDelay() { }
11+
12+
@memoize
13+
mem() { }
14+
15+
@memoize(true)
16+
memWithConfig() { }
17+
}

tsconfig.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"compilerOptions": {
3+
"module": "es2015",
4+
"target": "es2016",
5+
"lib": [
6+
"dom",
7+
"es2016"
8+
],
9+
"baseUrl": "./",
10+
"noImplicitAny": true,
11+
"experimentalDecorators": true,
12+
"sourceMap": false,
13+
"moduleResolution": "node",
14+
"strictNullChecks": true,
15+
"declaration": true,
16+
"noEmit": true,
17+
"pretty": true,
18+
"outDir": "ts-output"
19+
},
20+
"include": [
21+
"src/decko.d.ts",
22+
"tests/index.ts"
23+
]
24+
}

0 commit comments

Comments
 (0)