diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..00c9fe2 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,55 @@ +// Project: Immutability helper +// TypeScript Version: 2.2 + +export = update + +// declare function update(data: T, query: update.Query): T +declare function update( + data: ReadonlyArray, + query: ArrayOperators, +): ReadonlyArray + +declare function update( + data: ReadonlySet, + query: SetOperators, +): ReadonlySet + +declare function update( + data: ReadonlyMap, + query: MapOperators, +): ReadonlyMap + +declare function update(data: T, query: Query): object + +type Tree = {[K in keyof T]?: Query} +type Query = + | Tree + | ObjectOperators + | ArrayOperators + | SetOperators + +type ObjectOperators = + | {$set: any} + | {$toggle: Array} + | {$unset: Array} + | {$merge: Partial} + | {$apply: (old: T) => T} + | ((old: T) => any) +type ArrayOperators = + | {$push: T} + | {$unshift: T} + | {$splice: Array<[number, number]>} + +type MapOperators = {$add: Array<[K, V]>} | {$remove: K[]} +type SetOperators = {$add: T[]} | {$remove: T[]} + +declare namespace update { + function newContext(): typeof update + function extend( + command: Command, + handler: (param: CommandArg, old: T) => T, + ): void + + type Command = string + type CommandArg = any +} diff --git a/package.json b/package.json index 9829391..145f182 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "scripts": { "test-cov": "nyc npm test && nyc report --reporter=lcov", "test-travis": "nyc npm test && nyc report --reporter=lcov", - "test": "mocha test.js" + "test": "mocha test.js", + "test-dtslint": "dtslint" }, "keywords": [ "immutability" @@ -16,6 +17,7 @@ "license": "MIT", "devDependencies": { "coveralls": "^2.11.6", + "dtslint": "^0.2.0", "expect": "^1.14.0", "mocha": "^2.4.5", "nyc": "^5.6.0" diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..0d76f1b --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,15 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "noEmit": true, + "strictFunctionTypes": false, + + "baseUrl": ".", + "paths": { "immutability-helper": ["."] } + } +} + diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..e1e3a54 --- /dev/null +++ b/tslint.json @@ -0,0 +1,7 @@ +{ + "extends": "dtslint/dtslint.json", + "rules": { + "semicolon": false + } +} +