Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript annotations

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?

like image 552
Illorian Avatar asked Mar 15 '16 07:03

Illorian


People also ask

What are annotations in TypeScript?

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.

How do you annotate an object in TypeScript?

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.

What are decorators in TypeScript?

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.

What are annotations in angular?

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.


1 Answers

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.

like image 154
Amid Avatar answered Nov 10 '22 04:11

Amid