I am writing project on MarionetteJS using TS and I want to use annotations to register routes. For example:
@Controller
class SomeController {
@RouteMapping("some route")
public SomeMethod() {
//code
}
}
Is there opportunity to call method annotations when I create class instance?
TypeScript - Type Annotations TypeScript is a typed language, where we can specify the type of the variables, function parameters and object properties. We can specify the type using :Type after the name of the variable, parameter or property. There can be a space after the colon.
TypeScript uses type annotations to explicitly specify types for identifiers such variables, functions, objects, etc. TypeScript uses the syntax : type after an identifier as the type annotation, where type can be any valid type. Once an identifier is annotated with a type, it can be used as that type only.
A Decorator is a special kind of declaration that can be attached to a class declaration, method, accessor, property, or parameter. Decorators use the form @expression , where expression must evaluate to a function that will be called at runtime with information about the decorated declaration.
Although Annotations and Decorators both share the same @ symbol in Angular, they both are different language features. Annotations: These are hard-coded language feature. Annotations are only metadata set on the class that is used to reflect the metadata library.
No there isn't.
Check out this article Decorators & metadata reflection in TypeScript. It shows how decorators are transformed into pure javascript and therefore when they are called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With