-
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from piotrwitek/next
v2.0.0
- Loading branch information
Showing
11 changed files
with
876 additions
and
477 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "utility-types", | ||
"version": "1.1.0", | ||
"version": "2.0.0", | ||
"description": "Utility Types Library for TypeScript", | ||
"author": "Piotr Witek <[email protected]> (http://piotrwitek.github.io)", | ||
"repository": "https://github.com/piotrwitek/utility-types", | ||
|
@@ -28,25 +28,24 @@ | |
"build:jsnext": "rm -rf jsnext/ && tsc -p . --outDir jsnext/ -t 'ES2015'", | ||
"precommit": "npm run lint", | ||
"prepush": "npm run test", | ||
"prepublishOnly": "npm run clean && npm run reinstall && npm run lint && npm run tsc && npm run test && npm run build" | ||
"prepublishOnly": | ||
"npm run clean && npm run reinstall && npm run lint && npm run tsc && npm run test && npm run build" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@types/jest": "22.0.0", | ||
"@types/node": "6.0.95", | ||
"@types/jest": "22.2.2", | ||
"husky": "0.14.3", | ||
"jest-cli": "22.0.4", | ||
"redux": "3.7.2", | ||
"ts-jest": "22.0.0", | ||
"ts-node": "4.1.0", | ||
"tslib": "1.8.1", | ||
"tslint": "5.8.0", | ||
"typescript": "2.7.2" | ||
"jest": "22.4.3", | ||
"ts-jest": "22.4.2", | ||
"ts-node": "5.0.1", | ||
"tslib": "1.9.0", | ||
"tslint": "5.9.1", | ||
"typescript": "2.8.1" | ||
}, | ||
"keywords": [ | ||
"utility-types", | ||
"typescript", | ||
"utilities", | ||
"utility", | ||
"types", | ||
"static-typing", | ||
"mapped-types", | ||
"flow", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// type Unionize<T> = { [P in keyof T]: { [Q in P]: T[P] } }[keyof T]; | ||
|
||
// type GetComponentProps<T> = | ||
// T extends new (props: infer P) => any ? P : | ||
// T extends (props: infer P & { children?: React.ReactNode }) => any ? P : | ||
// any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,18 @@ | ||
import { testType } from './test-utils'; | ||
import { $call, getReturnOfExpression } from '.'; | ||
import { getReturnOfExpression } from '.'; | ||
|
||
//#region Docs Example | ||
const increment = () => ({ type: 'INCREMENT' as 'INCREMENT' }); | ||
|
||
const returnOfIncrement = $call(increment); | ||
const returnOfIncrement = getReturnOfExpression(increment); | ||
type IncrementAction = typeof returnOfIncrement; // { type: "INCREMENT"; } | ||
//#endregion | ||
|
||
describe('Type Utils', () => { | ||
describe('$call', () => { | ||
it('should return null value', () => { | ||
expect(returnOfIncrement).toBe(undefined); | ||
testType<{ type: 'INCREMENT'; }>(returnOfIncrement); | ||
}); | ||
it('should be equal with alias returntypeof', () => { | ||
expect($call).toBe(getReturnOfExpression); | ||
testType<{ type: 'INCREMENT' }>(returnOfIncrement); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,13 @@ | ||
// Copyright (c) 2016 Piotr Witek <[email protected]> (http://piotrwitek.github.io) | ||
// (tracking issue: https://github.com/Microsoft/TypeScript/issues/6606) | ||
|
||
/** | ||
* @function $call | ||
* @alias getReturnOfExpression | ||
* @function getReturnOfExpression | ||
* @deprecated from TS v2.8 use built-in ReturnType<T> or $Call API | ||
* @description infer the return type from a given "expression" (at runtime it's equivalent of "noop") | ||
* @template RT - Return Type | ||
* @template RT - ReturnType | ||
* @param expression: (...params: any[]) => RT | ||
* @returns undefined as RT | ||
*/ | ||
export function $call<RT>( | ||
expression: (...params: any[]) => RT, | ||
): RT { | ||
return undefined as any as RT; | ||
export function getReturnOfExpression<RT>(expression: (...params: any[]) => RT): RT { | ||
return (undefined as any) as RT; | ||
} | ||
|
||
// ALIAS | ||
export const getReturnOfExpression = $call; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.