Last active
November 13, 2018 04:26
-
-
Save ifiokjr/c7d7c6ea40ecd6ec16fa2ef0bb7b2706 to your computer and use it in GitHub Desktop.
TS code samples
This file contains hidden or 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
/** | |
* Jest tests can be destructured. However it won't work with inlineSnapshots | |
*/ | |
const thrower = () => { | |
throw new Error('test'); | |
}; | |
const simple = () => { | |
// | |
}; | |
test('#baseDefinition', () => { | |
let t = true; | |
const { not, toThrow } = expect(() => (t ? thrower() : simple())); | |
toThrow(); | |
t = false; | |
not.toThrow(); | |
}); |
This file contains hidden or 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
// Replace return type | |
/** | |
* Helper for retrieving the argument type of a function | |
*/ | |
export type ArgumentTypes<T> = T extends (...args: Array<infer U>) => any ? U : never; | |
/** | |
* Replace that argument type | |
*/ | |
type ReplaceReturnType<T, TNewReturn> = (...a: ArgumentTypes<T>) => TNewReturn; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment