simplytyped
Advanced tools
Comparing version 1.2.5 to 1.3.0
{ | ||
"name": "simplytyped", | ||
"version": "1.2.5", | ||
"version": "1.3.0", | ||
"description": "yet another Typescript type library for advanced types", | ||
@@ -37,4 +37,4 @@ "main": "index", | ||
"devDependencies": { | ||
"@commitlint/config-conventional": "^6.1.3", | ||
"@types/node": "~10.1.0", | ||
"@commitlint/config-conventional": "^7.0.0", | ||
"@types/node": "~10.3.0", | ||
"ava": "~0.25.0", | ||
@@ -41,0 +41,0 @@ "commitlint": "^7.0.0", |
@@ -43,3 +43,3 @@ # SimplyTyped | ||
[Predicate](#predicate) - [ConstructorFunction](#constructorfunction) - [AnyFunc](#anyfunc) - [Readonly](#readonly) - [isKeyOf](#isKeyOf) - [objectKeys](#objectkeys) | ||
[Predicate](#predicate) - [ConstructorFunction](#constructorfunction) - [AnyFunc](#anyfunc) - [OverwriteReturn](#overwritereturn) - [Readonly](#readonly) - [isKeyOf](#isKeyOf) - [objectKeys](#objectkeys) | ||
@@ -474,2 +474,9 @@ **[Utils](#utils)** | ||
### OverwriteReturn | ||
Can change the return type of any function while maintaining the function arguments. (up to 7 arguments) | ||
```ts | ||
type F = (x: 'hi', y: 'there') => number; | ||
type got = OverwriteReturn<F, string>; // => (x: 'hi', y: 'there') => string; | ||
``` | ||
### Readonly | ||
@@ -476,0 +483,0 @@ This takes a runtime object and makes its properties readonly. |
@@ -6,1 +6,2 @@ import { If } from './conditionals'; | ||
export declare type AnyFunc<R = any> = (...args: any[]) => R; | ||
export declare type OverwriteReturn<F extends AnyFunc, R> = F extends () => any ? () => R : F extends (x1: infer X1) => any ? (x1: X1) => R : F extends (x1: infer X1, x2: infer X2) => any ? (x1: X1, x2: X2) => R : F extends (x1: infer X1, x2: infer X2, x3: infer X3) => any ? (x1: X1, x2: X2, x3: X3) => R : F extends (x1: infer X1, x2: infer X2, x3: infer X3, x4: infer X4) => any ? (x1: X1, x2: X2, x3: X3, x4: X4) => R : F extends (x1: infer X1, x2: infer X2, x3: infer X3, x4: infer X4, x5: infer X5) => any ? (x1: X1, x2: X2, x3: X3, x4: X4, x5: X5) => R : F extends (x1: infer X1, x2: infer X2, x3: infer X3, x4: infer X4, x5: infer X5, x6: infer X6) => any ? (x1: X1, x2: X2, x3: X3, x4: X4, x5: X5, x6: X6) => R : F extends (x1: infer X1, x2: infer X2, x3: infer X3, x4: infer X4, x5: infer X5, x6: infer X6, x7: infer X7) => any ? (x1: X1, x2: X2, x3: X3, x4: X4, x5: X5, x6: X6, x7: X7) => R : AnyFunc<R>; |
28383
214
510