Skip to content

Instantly share code, notes, and snippets.

@fdecampredon
Last active August 10, 2019 22:03
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save fdecampredon/86527d5da35b67da4c89 to your computer and use it in GitHub Desktop.
Save fdecampredon/86527d5da35b67da4c89 to your computer and use it in GitHub Desktop.
Contract programming with typescript and decorators
@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>
}
}
@SoEasy
Copy link

SoEasy commented Dec 12, 2017

Hello! Could you rate my implementation of such decorators?
https://gist.github.com/SoEasy/5df7b9768463c44804d2773d043fd2fd
Sincerely, Vladimir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment