Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the @ symbol in TypeScript?

Why in components or directives do the metadata or decorators have the @ symbol (e.g. @Component, @Directive)?

What is the purpose of it, and when should I use it?

like image 439
Adrian Avatar asked Feb 24 '17 05:02

Adrian


People also ask

What does !: Mean in TypeScript?

Save this answer. Show activity on this post. That is a "definite assignment assertion": varname !: sometype informs typescript not to worry about checking if varname might be unassigned (it tells typescript that varname will definitely be assigned, even if typescript cannot infer where it is assigned).

What is unique symbol in TypeScript?

unique symbol is a subtype of symbol , and are produced only from calling Symbol() or Symbol. for() , or from explicit type annotations. The new type is only allowed on const declarations and readonly static properties, and in order to reference a specific unique symbol, you'll have to use the typeof operator.

What is symbol () in JS?

Symbol is a built-in object whose constructor returns a symbol primitive — also called a Symbol value or just a Symbol — that's guaranteed to be unique.

What does pipe mean in TypeScript?

In Typescript, pipe(|) is referred to as a union type or “Or”. it is also called union type in typescript.


1 Answers

It stands for decorators. It is not TypeScript specific.

Google "javascript decorator" to learn more about it.

For example:

http://javascript.info/tutorial/decorators

https://medium.com/google-developers/exploring-es7-decorators-76ecb65fb841#.jzu13e5lr

For up to date information about their standard implementation and when it will finally be released (future ECMAScript versions), see this page: https://github.com/tc39/proposal-decorators

And as @hardikModha mentioned, you can also look up the TypeScript handbook: http://www.typescriptlang.org/docs/handbook/decorators.html

like image 96
unional Avatar answered Oct 03 '22 20:10

unional