Created
April 23, 2015 13:17
-
-
Save michelsalib/cfff8114ce081930a453 to your computer and use it in GitHub Desktop.
Typescript @deprecated annotation
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
class Dog { | |
@deprecated('Dogs don\'t roar, they talk.') | |
roar() { | |
console.log('RRRRR'); | |
} | |
@deprecated() | |
smile() { | |
console.log('smile'); | |
} | |
walk() { | |
console.log('walk'); | |
} | |
} | |
function deprecated(message: string = 'Function {name} is deprecated.') { | |
return (instance, name, descriptor) => { | |
var original = descriptor.value; | |
var localMessage = message.replace('{name}', name); | |
descriptor.value = function() { | |
console.warn(localMessage); | |
return original.apply(instance, arguments); | |
}; | |
return descriptor; | |
}; | |
} | |
// create my dog | |
var d = new Dog(); | |
d.roar(); | |
d.smile(); | |
d.walk(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another issue, the line
25
usesinstance
which will causethis
issue. Change it tothis
will be OK: