Last active
August 10, 2019 22:03
-
-
Save fdecampredon/86527d5da35b67da4c89 to your computer and use it in GitHub Desktop.
Contract programming with typescript and decorators
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
@In((a: string, b: string) => { | |
assert(typeof a === 'string'); | |
assert(typeof b === 'string'); | |
assert(a.length > 5); | |
assert(a.length > 7); | |
}) | |
@Out((result: string) => { | |
assert(typeof result === 'string'); | |
assert(a.length > 12); | |
}) | |
export const myFunc = (a: string, b: string): string => { | |
return a + b; | |
} | |
//if possible | |
@In((a: string, b: string) => { | |
assert(typeof a === 'string'); | |
assert(typeof b === 'string'); | |
assert(a.length > 5); | |
assert(a.length > 7); | |
}) | |
@Out((result: string) => { | |
assert(typeof result === 'string'); | |
assert(a.length > 12); | |
}) | |
function myFunc(a: string, b: string): string { | |
return a + b; | |
} | |
@Invariant((myComp) => { | |
assert(typeof myComp.props.name === 'string'); | |
}) | |
class MyComp extends React.Component { | |
render() { | |
<span>{this.props.name}</span> | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello! Could you rate my implementation of such decorators?
https://gist.github.com/SoEasy/5df7b9768463c44804d2773d043fd2fd
Sincerely, Vladimir.